Eclipse JUnit4:使用名称模式排除测试 [英] Eclipse JUnit4: exclude tests using a name pattern

查看:134
本文介绍了Eclipse JUnit4:使用名称模式排除测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Eclipse的JUnit Run配置中指定一个名称模式(例如**/integration/* Test),在运行项目的所有测试时应将其从测试运行中排除?

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?

查看运行/调试配置"中的选项,我认为这个问题可以简化为:是否可以排除基于junitRunner命令行参数的某些测试.

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.

我对创建(和维护)另一种替代解决方案(尽管仍然对此不感兴趣)是创建以分离包含测试文件的目录:

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

  • yourProject/测试
  • 您的项目/集成测试

并选择该目录以在其中运行所有测试(或在运行配置"的测试"选项卡中更改在所选项目,程序包或源文件夹中运行所有测试").

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).

我正在使用:

  • Eclipse 3.5
  • JUnit 4

任何提示/建议都非常感谢!

Any tips/advice greatly appreciated!

推荐答案

您可以扩展Suite类,覆盖

You could extend the Suite class, override

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

,但不是带注释的类,而是返回所需的类.我敢打赌,有很多方法可以做到这一点,但我可以扫描classpath的classes文件夹,找到其中的所有测试类,然后忽略您不喜欢的类. Class.forName会将名称转换为Classs.

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.

您甚至可以执行jUnit4样式的注释

You could even do jUnit4-style annotation

@RunWith(IgnoreSuite.class)
@IgnoreTests("integration")
public class NormalTests {
}

这篇关于Eclipse JUnit4:使用名称模式排除测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆