How to write unit test in situations where it is obvious, "looking" at the fact that the test passed?

Sometimes I come across situations where all I need to check is whether the program execution reaches a certain point without any exceptions or the program is interrupted or falls into an infinite loop or something like that.

I do not understand how to write unit test for this.

For example, consider the following "unit test" -

@Test
public void testProgramExecution()
  {
     Program program = new Program();
     program.executeStep1();
     program.executeStep2();
     program.executeStep3();

     // if execution reaches this point, that means the program ran successfully. 
     // But what is the best practice?
     // If I leave it like this, the test will "pass", 
     // but I am not sure if this is good practice. 
  }

Usually, at the end of the test, I have an operator like -

assertEquals(expectedString, actualString);

But how to write assertEquals or another type of test instruction for the above case?

+5
source share
3 answers

Your code looks good, just delete the comments, but leave this:

// If execution reaches this point, that means the program ran successfully.

, .

, , , - , , " ".

, , , , , , " ", :

// No assertions have been made here because the state is unpredictable.
// Any problems with execution will be detected during integration tests.
+5

, , , , . , , , . , .

, , , , , , . , , [0, 100], "" , -1 101, 0 100 , .

+2

In such situations, I just insert

assertTrue(true);

at the end of the function ...

+2
source

All Articles