How to add a JUnit 4 test to a JUnit 3 test suite
Asked Answered
E

1

5

I want to add a JUnit 4 test to a legacy project which uses JUnit 3 test suites ("AllTests") to organize the tests.

The tests are already executed with JUnit 4, so I know that JUnit 4 tests work in principle. I just forgot how to add the JUnit 4 test class to the junit.framework.TestSuite instance. Anyone with the code snippet?

Excretory answered 25/10, 2013 at 13:51 Comment(0)
E
10

It's as easy as this:

public static Test suite() {
    TestSuite suite = new TestSuite("suite name");
    suite.addTestSuite(JUnit3Test.class);

    suite.addTest(new JUnit4TestAdapter(JUnit4Test.class));  // <--

    return suite;
}
Excretory answered 25/10, 2013 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.