开发者

Eclipse JUnit4: exclude tests using a name pattern

Is it possible to specify in the JUnit Run configuration in Eclipse a name pattern (say **/integration/*Test) that should be exclud开发者_开发技巧ed 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!


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 {
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜