How to write a unit test in situations where it is obvious by "looking" that the test passed?
java, unit-testing
Solution
Your code looks fine, just remove the comments, but leave this one:
// If execution reaches this point, that means the program ran successfully.
So readers of your code will understand why there are no assertions.
It is worth noting that every method called in your test should have some kind of effect, and that effect should be asserted as having happened correctly, even if you say "you don't care".
If you insist there is no need to check, add a comment to explain why - this will save readers from trawling through your code to find out for themselves why "it doesn't matter", for example:
// No assertions have been made here because the state is unpredictable.
// Any problems with execution will be detected during integration tests.
Problem
Sometimes, I encounter situations where all I need to test is whether the program's execution reaches a certain point without any exceptions being thrown or the program being interrupted or getting caught in an infinite loop or something. What I don't understand is how to write a unit test for that. For instance, 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 a test, I have a statement like- ``` assertEquals(expectedString, actualString); ``` But how to write an assertEquals or other type of test statement for the above case?