Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse JUnit4: exclude tests using a name pattern

Tags:

junit

eclipse

Is it possible to specify in the JUnit Run configuration in Eclipse a name pattern (say **/integration/*Test) that should be excluded from the test run when running all tests of a project?

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

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

Another alternative solution (still not interested in that one, though) is to create to separate directories containing test files:

  • yourProject/tests
  • yourProject/integration-tests

and selecting that directory in order to run all tests in it (or changing the "Run all tests in the selected project, package or source folder" in the Test tab of the Run Configuration).

I'm using:

  • Eclipse 3.5
  • JUnit 4

Any tips/advice greatly appreciated!

like image 902
Maciej Biłas Avatar asked Mar 03 '10 14:03

Maciej Biłas


1 Answers

You could extend the Suite class, override

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

but instead of annotated classes return classes you want. I bet there is a lot of ways to do it, but Id scan the classpath for classes folder, find all test classes inside and ignore the ones you dont like. Class.forName will turn names into Classes.

You could even do jUnit4-style annotation

@RunWith(IgnoreSuite.class)
@IgnoreTests("integration")
public class NormalTests {
}
like image 84
IAdapter Avatar answered Sep 19 '22 14:09

IAdapter