Eclipse JUnit4: exclude tests using name template

Is it possible to specify a name template (for example, ** / integration / * Test) in the JUnit Run configuration in Eclipse that should be excluded from the test run when all project tests are performed?

Looking at the parameters in the Run / Debug configuration, I assume that this question could be reduced to: is it possible to exclude certain tests based on the junit runner command line parameters.

I'm not interested in creating (and maintaining) Test Suites .

Another alternative solution (still not interested in this) is to create separate directories containing test files:

  • yourProject / tests
  • yourProject / integration tests

and selecting this directory to run all the tests in it (or the change "Run all tests in the selected project, package or source folder" on the "Test" tab in the "Run Configuration").

I use:

  • Eclipse 3.5
  • Junit 4

Any advice / advice was rated very highly!

+7
eclipse junit
source share
1 answer

You can extend the Suite class, override

public Suite(Class klass, RunnerBuilder builder) throws InitializationError { this(builder, klass, getAnnotatedClasses(klass)); } 

but instead of annotated classes, the desired classes are returned. I bet there are many ways to do this, but Id scans the classpath for the class folder, find all the test classes inside and ignore the ones you don't like. Class.forName will turn names into classes.

You can even make jUnit4 annotation

 @RunWith(IgnoreSuite.class) @IgnoreTests("integration") public class NormalTests { } 
+2
source share

All Articles