public class MyTests extends TestCase
{
@Test
public testOne()
{
//do stuff
}
@Test
public anotherTest()
{
//do stuff
}
}
Using JUnit 4, it would appear that both these tests are run, but actually only the first one runs. Why? Because the class extends TestCase, so JUnit 4 will handle this class using a JUnit 3 compatibility mode. This means that the @Test tag is ignored and the method names are examined for the pattern "test*". This can be fixed in two ways. The first is by removing "extends TestCase". This will cause JUnit 4 to run the test in normal mode instead of backwards compat mode.
The second option is to use a class annotation to force the class to be treated as a JUnit 4 test case. It looks like this:
@RunWith(JUnit4.class)
public class MyTests extends TestCase
{
...
}
This forces JUnit 4 to locate tests using annotations instead of using the older method name convention.
The solution using @RunWith was found in the JUnit yahoo group.
2 comments:
thank you
Great solution (@RunWith(JUnit4.class)
Post a Comment