How can I specify JUnit test dependencies?
Our toolkit has over 15000 JUnit tests, and many tests are known to fail if some other test fails. For example, if the method X.foo() uses functionality from Y.bar() and YTest.testBar() fails, then XTest.testFoo() will fail too. Obviously, XTest.testFoo() can also fail because of problems specific to X.foo().
While this is fine and I still want both tests run, it would be nice if one could annotate a test dependency with XTest.testFoo() pointing to YTest.testBar(). This way, one could immediately see what functionality used by X.foo() is also failing, and what not.
Is there such annotation available in JUnit or elsewhere? Something like:
public XTest {
@Test
@DependsOn(method=org.example.tests.YTest#testBar)
public void testFoo() {
// Assert.something();
}
}
Solution 1:
JExample and TestNG have something like that.
I don't know how useful it is, but if you try it, please come back to tell us whether it was useful.
Solution 2:
There's a contribution to JUnit that address this: https://github.com/junit-team/junit.contrib/tree/master/assumes