How to get Junit 4 to ignore a Base Test Class?

Allain Lalonde picture Allain Lalonde · Jan 20, 2009 · Viewed 43k times · Source

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?

Answer

guerda picture guerda · Jan 20, 2009

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