Alex Rivera | Logout

Running "pure" JUnit 4 tests using ant

Asked 2009-03-11T17:08:23.187
24

We have migrated to both JUnit 4 and ant 1.7

The tests runs fine in eclipse, but the annotations are ignored when running the tests using ant.

According to the Ant junit task documentation:

It also works with JUnit 4.0, including "pure" JUnit 4 tests using only annotations and no JUnit4TestAdapter.

But the documentation doesn't elaborate on how it should be configured.

Is there any special setting required for the junit task? Am I missing something? We have both Tests that extends TestCase (i.e. 3.8 style) and "pure" Junit 4 tests, could that be the problem?

Edit
Report

1 Answer

2

This happened to me and it was because I was both using annotations and extending TestCase.

public class TestXXX extends TestCase {

    @Test
    public void testSimpleValidCase() {
        // this was running
    }

    @Test
    public void simpleValidCase() {
        // this wasn't running
    }
}

When you extend TestCase you are assuming JUnit3 style so JUnit4 annotations are ignored.

The solution is to stop extending TestCase.

answered 2012-03-21T12:08:41.480

Your Answer