I had a failing unit test and wondered why. I found out that the test is executed 400 times. Trying to figure out what causes the test to execute so many times, I reduced the code to the following:
package reproduce; import org.junit.After; import org.junit.Test; import static org.junit.experimental.results.PrintableResult.testResult; public class FailingTest { static int objCount = 0; public FailingTest() { objCount++; } @Test public void test() { System.out.println(objCount); } @After public void tearDown() { testResult(FailingTest.class); // comment this to run only once } } In my tearDown() method, I'm trying to find out the result of the tests, because my cleanup operation could takes some minutes, so I only want to clean up in case of a failure, but not in case of succcess.
I found the use of testResult() in code of the verifier rule and thought it would be useful for me, but it won't be useful if my tests are run 400 times as often.
Is that a bug of the experimental PrintableResult, am I doing something wrong or is there another/easier way of achieving my intended result?