Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In order to test a Map class I have defined, I have extended MapInterfaceTest from the Google Collections library.

The problem is I want to add more tests to this class, and be able to ignore specific long-running or broken ones with the @Ignore annotation while developing, but because MapInterfaceTest extends TestCase, the tests are run in Junit3 compatibility mode, and the annotations are ignored.

Is there any way to get Junit to respect the annotations on a test class which extends TestCase?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
354 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this annotation at your test class.

@RunWith(JUnit4.class)
public class MyTestCase extends MapInterfaceTest {...}

This should force Junit to use Junit4 not Junit3 in the execution. Maybe that works for your Testcase.

However, JUnit4 will not pick up old-style "test*" test methods, as it relies on @Test annotations. If the class you're extending doesn't have these annotations and you can't add them directly, you can override the tests in order to add the annotations in the subclass, like so:

@Test
@Override
public void testFoo()
{
    super.testFoo();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...