I've managed to find out how to make a TestSuite in jUnit 4, but I really miss the v3 possibility of wrapping a suite in a TestSetup.
Any ideas as to how to get some @BeforeClass/@AfterClass setup executed for a suite of test cases in jUnit 4?
I.e.
@RunWith(Suite.class)
@Suite.SuiteClasses({Test1.class, Test2.class})
public class MyTestSuite {
@BeforeClass public static void setUpClass() {
// Common initialization done once for Test1 + Test2
}
@AfterClass public static void tearDownClass() {
// Common cleanup for all tests
}
}
Unfortunately the above code fragment doesn't work. @BeforeClass
only works on a per-test-class basis.
Here is what I have and it runs just fine.
Here is my test suite 1 (do the same for test suite 2).
And here is my test class. Create both testcase1 and testcase2.
you should have 5 classes completesuite suite1 suite2 test1 test2
and make sure you have Junit in your build path. This should run!
Here is the output