整理 JUnit 4 动态套件的详细信息
您好 – 我希望将 JUnit 测试自动扫描到套件中,作为连续构建的一部分,因此我从 JUnit 的套件中派生了一个运行程序,它可以查找包中的所有测试类。 跑步者工作得很好,但结果显示低于预期。
我的测试支持包中有一个类,带有针对我的跑步者的 @RunWith 注释。 运行程序通过读取属性来获取正在测试的包。 设置该属性并告诉 JUnit 运行带注释的类,并执行该包中的所有测试。 在 Ant 和 IntelliJ 中,套件的名称被报告为具有 @RunWith 注释的类的名称。 我的跑步者有一个对 ParentRunner.getName() 的覆盖,它返回被测试的包的名称。 我验证了该字符串是否已进入跑步者的描述对象。 我缺少什么?
环境:
- JUnit:4.5
- Ant:1.7.0
- IntelliJ IDEA:8.1
感谢您提供的任何指导。
Hi – I wanted to automatically sweep JUnit tests into suites as part of my continuous builds, so I derived a runner from JUnit's Suite which finds all test classes in a package. The runner works just fine, but the results display is less than expected.
I have one class in my testing support package with a @RunWith annotation for my runner. The runner works by reading a property to get the package under test. Set the property and tell JUnit to run the annotated class, and all tests in that package are executed. The name of the suite is reported as the name of the class which has the @RunWith annotation, in both Ant and IntelliJ. My runner has an override for ParentRunner.getName() which returns the name of the package under test. I verified that the string gets into the runner's Description object. What am I missing?
Environment:
- JUnit: 4.5
- Ant: 1.7.0
- IntelliJ IDEA: 8.1
Thanks for whatever direction you can provide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为 ANT 和 IntelliJ 使用自己的运行器,因此它们是根据测试构建名称,而不是从您的运行器获取名称。 换句话说,运行程序被委托是为了运行测试,而不是为了描述测试。
This is because ANT and IntelliJ use their own runners, so they are building the name based on the test, and not getting the name from your runner. In other words, the runner is delegated to for the purpose of running the test, but not for the purpose of describing it.
几周前我遇到了类似的问题,并因此创建了一个开源项目。
您可以通过 Maven 包含它
或从 github 页面下载它,您也可以在其中找到它的文档。
https://github.com/cschoell/Junit-DynamicSuite
其中包含一个 Junit 运行程序,允许扫描目录或类路径以进行单元测试,并通过实现简单的接口来过滤它们。
I had a similar problem just a few weeks ago and created an open source project because of it.
You may include it via maven
or download it from the github page, where you will find its documentation as well.
https://github.com/cschoell/Junit-DynamicSuite
There is a Junit runner included which allows to scan either a directory or the classpath for unit tests and filter them by implementing a simple interface.