Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();   }  } 
like image 603
Egon Willighagen Avatar asked Apr 06 '10 12:04

Egon Willighagen


People also ask

What is the dependency for JUnit?

The junit-jupiter-api dependency provides the public API that allows us to write tests and extensions which use JUnit 5. The junit-jupiter-engine dependency ensures that the Maven Surefire Plugin can run tests which use JUnit 5.

Is dependency test supported by JUnit?

Said libraries provide their own test runner, which supports their dependency mechanism. And both can be used alongside JUnit (without need to rewrite existing classes).

What are dependencies in unit testing?

So, what is a unit testing dependency? It's a dependency that you must set up in the test before you can exercise the system under test. Dependencies can be explicit, like in the example above, but they also can be implicit.


1 Answers

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.

like image 120
Esko Luontola Avatar answered Sep 17 '22 16:09

Esko Luontola