'Running JUnit 3 tests with JUnit Vintage engine
In our project we have quite a few JUnit 3 tests looking like:
@RunWith(AllTests.class)
public class JUnit3Test extends TestCase {
public static TestSuite suite()
{
var suite = new TestSuite("JUnit 3 style test suite");
suite.addTest(new JUnit3Test("JUnit 3 style test") {
@Override
protected void runTest() {
testSomething();
}
});
return suite;
}
public void testSomething() {
...
}
...
}
Currently, we're executing them using JUnit 4, but I'm trying to move to JUnit 5. When I change to useJUnitPlatform() in the Gradle build file these tests are no longer executed.
There's a full working example in https://github.com/ulrikls/junit-vintage-alltests
Any of these changes will successfully execute the JUnit 3 test:
- Switching to JUnit 4 -
useJUnit()instead ofuseJUnitPlatform(). - Changing the name of the test from
JUnit 3 style testtotestSomeLibraryMethodReturnsTrue. - Removing the
@RunWith(AllTests.class)annotation and thesuite()method.
I don't know if this example is even supposed to work in JUnit 5, there doesn't seem to be a lot of documentation on running JUnit 3 tests with JUnit 5. But migrating all our JUnit 3 tests is also not trivial, as the tests do various stuff in the suite() method.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
