问题描述
我从JUnit3.8切换到JUnit4.4。我使用蚂蚁运行我的测试中,我的所有测试成功运行,但测试工具类失败,没有可运行的方法的错误。我使用的模式是包括测试文件夹下一个名为*测试*所有类。
I have switched to JUnit4.4 from JUnit3.8. I run my tests using ant, all my tests run successfully but test utility classes fail with "No runnable methods" error. The pattern I am using is to include all classes with name *Test* under test folder.
据我所知,亚军无法找到@Test注解属性的任何方法。但他们并没有包含这样的注释,因为这些类不测试。
令人惊讶的日食中运行这些测试时,它不会抱怨这些类。
I understand that the runner can't find any method annotated with @Test attribute. But they don't contain such annotation because these classes are not tests.Surprisingly when running these tests in eclipse, it doesn't complain about these classes.
在JUnit3.8这不是一个问题,因为在所有这些工具类没有扩展TestCase所以亚军并没有试图执行它们。
In JUnit3.8 it wasn't a problem at all since these utility classes didn't extend TestCase so the runner didn't try to execute them.
我知道我可以在Ant脚本排除在JUnit目标这些具体的类。但是我不想在每一个新的实用工具类,我添加到更改构建文件。我还可以重命名类(但上课提供良好的名称一直是我最弱的天赋:-))
I know I can exclude these specific classes in the junit target in ant script. But I don't want to change the build file upon every new utility class I add. I can also rename the classes (but giving good names to classes was always my weakest talent :-) )
有没有针对此问题的任何优雅的解决方案?
Is there any elegant solution for this problem?
推荐答案
假设你在用于查找测试类图案的掌控,我建议改变以匹配 *测试
,而不是 *测试*
。这样 TestHelper
不会得到匹配,但 FooTest
会。
Assuming you're in control of the pattern used to find test classes, I'd suggest changing it to match *Test
rather than *Test*
. That way TestHelper
won't get matched, but FooTest
will.
这篇关于JUnit的:如何避免"没有可运行的方法"在测试utils的课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!