Eclipse JUnit4: exclude tests using a name pattern

元气小坏坏 提交于 2019-12-21 12:02:07

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/2372042/eclipse-junit4-exclude-tests-using-a-name-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!