tags:

views:

905

answers:

2

I have a base class for many tests that has some helper methods they all need.

It does not by itself have any tests on it, but JUnit (in eclipse) is invoking the test runner on it and complaining that there are no methods to test.

How can I make it ignore this class?

I know I could add a dummyTest method that would solve the problem, but it would also appear for all the children classes.

Suggestions?

+7  A: 

Use to @Ignore annotation. It also works on classes. See this one:

@Ignore public class IgnoreMe {
                        @Test public void test1() { ... }
                        @Test public void test2() { ... }
                }

Also, you can annotate a class containing test methods with @Ignore and none of the containing tests will be executed.

Source: JUnit JavaDoc

furtelwart
I agree that this should work, so +1. Except with netbeans 6.2 and jUnit 4.5 @ignore is listed as only being valid for Methods.
Allain Lalonde
Looking it up and Libary's called 4.5 but the jar is junit4-1.jar weird. Accepted your answer. Thanks.
Allain Lalonde
+4  A: 

Just as a note, I'd always recommend giving a reason for the ignore:

@Ignore("This test will prove bug #123 is fixed, once someone fixes it")

I'm hoping the junit xml report formatter, used when running tests from ant, will one day include the ignored count (and the reasons) along with pass, fail, and error.

floater81
I'm looking forward to that too now. :) thanks
Allain Lalonde