how can I use JUnit to not terminate on assertion failures, but just log them?
My goal is to fail if log messages exist, and print them out. Because I’d like to iterate over a big list, and want to know which elements fail.
How can I force JUnit to not break on failures?
ty
You can’t do what you want with standard JUnit, with your tests as they are. The problem is that assertXXX methods actually throw Exceptions (AssertionError), so you can’t use normal asserts and resume from the point after the exception has been thrown. JUnit catches these AssertIonErrors and does the right thing.
One alternative is to use, as Ludwig suggested, the ErrorCollector rule, but it will mean rewriting a fair portion of your tests I would imagine.
If your goal is to iterate over a large list, look at Parameterized. This allows you to iterate over single test method, with different data each time:
data() returns a list of Object[]. Each Object[] in the list is passed to the constructor of the test class. So a new instance of the test class is used for each entry in the list.
The number of entries in the Object[] must correspond to the number of parameters to the constructor, and the types have to correspond as well.