Do not let the test stop when it fails.

I am looking for best practice for the following (simplified) scenario:

@Test public void someTest() { for(String someText : someTexts) { Assert.true(checkForValidity(someText)); } } 

This test is repeated through x-thousand texts, and in this case I do not want it to be stopped for every failure. I want the errors to be buffered, and in case of errors (errors) at the end. Did JUnit get anything on board for my purpose?

+2
source share
1 answer

First of all, this is not the right way to implement this. JUnit allows you to parameterize tests by defining a collection of inputs / outputs with the Parametrized test runner. The implementation of this method ensures that each test case becomes a unique instance in which the test report clearly indicates which samples passed and which failed.

If you still insist on doing it your own way, you should take a look at AssertJ Soft Assertions , which allow you to β€œswallow” individual statement failures, accumulating them only after the test is completed. The related documentation section uses a good example and is definitely worth a read.

+5
source

All Articles