Tuesday, December 28, 2010

Creating test suites with Junit4

Test Suite can be created in JUnit 4 as

import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({TestClass1.class, TestClass2.class})
public class TestSuite {
//nothing
}


The @RunWith(Suite.class) gives opportunity to combine both JUnit 4 and JUnit 3 tests and test cases together:


@RunWith(Suite.class)
@Suite.SuiteClasses({
ExampleOfJunit3TestSuite.class,
ExampleOfJUnit3TestCase.class,
ExampleOfJUnit4TestSuite.class,
ExampleOfJUnit4TestCase.class})
public class BothJUnit4and3TestSuite {
}


The Both JUnit4 and 3 TestSuite runs all tests and test suites listed in @Suite.SuiteClasses.

No comments:

Post a Comment