You seem to be using Junit 3.x. From Junit 4.0, your test case class doesn't need to extend TestCase
. It just needs to have methods annotated with @Test
, @Before
, @After
, @BeforeClass
, @AfterClass
etc., as required. This would allow your test case class to extend some other class.
In our project, we run JUnit tests using Spring test runner and need to associate a couple of annotations with each test case. We address this by defining an abstract test case, associate the annotations with this abstract test case, and make every other test case extend this.
@RunWith(SpringJunit4TestRunner.class)
@ContextConfiguration(location={})
public class AbstractTestCase
{
}
public class ConcreteTestCase extends AbstractTestCase
{
@Before
public void setUp()
{
// Some set up before each test.
}
@Test
public void test1()
{
// Some test
}
@Test
public void test2()
{
// Some other test
}
@After
public void tearDown()
{
// Some tear down process after each test.
}
}