Recently a new concept of Theories was added to JUnit (since v4.4).
In a nutshell, you can mark your test method with @Theory
annotation (instead of @Test
), make your test method parametrized and declare an array of parameters, marked with @DataPoints
annotation somewhere in the same class.
JUnit will sequentially run your parametrized test method passing parameters retrieved from @DataPoints
one after another. But only until the first such invocation fails (due to any reason).
The concept seems to be very similar to @DataProviders
from TestNG, but when we use data providers, all the scenarios are run inspite of their execution results. And it's useful because you can see how many scenarious work/don't work and you can fix your program more effectively.
So, I wonder what's the reason not to execute @Theory
-marked method for every @DataPoint
? (It appears not so difficult to inherit from Theories runner and make a custom runner which will ignore failures but why don't we have such behaviour out of the box?)
UPD: I have created a fault-tolerant version of Theories runner and made it available for a public access: https://github.com/rgorodischer/fault-tolerant-theories
In order to compare it with the standard Theories runner run StandardTheoriesBehaviorDemo then FaultTolerantTheoriesBehaviorDemo which are placed under src/test/...
folder.