【发布时间】:2011-06-03 10:40:46
【问题描述】:
我在类似于this answer 中描述的设置中使用 JUnit 类别和 ClassPathSuite。回顾一下:
public interface FastTests {
}
@RunWith(Categories.class)
@Categories.IncludeCategory(FastTests.class)
@Suite.SuiteClasses(AllTests.class)
public class FastTestSuite {
}
@RunWith(ClasspathSuite.class)
public class AllTests {
}
...AllTests 使用了ClasspathSuite 库。
属于 FastTests 类别的测试类如下所示:
@Category(FastTests.class)
public class StringUtilsTest {
// ...
}
当我在我的 IDE 中运行“FastTestSuite”时,所有带有 FastTests 注释的测试都会执行,非常流畅:
现在,我想用 Ant 做同样的事情。 (令我惊讶的是,我在 SO 上找不到这方面的说明。)换句话说,我需要一个 Ant 目标,它使用 FastTests 注释运行所有测试。
我尝试了一些使用<test> 或<batchtest> 的简单方法...
<junit showoutput="true" printsummary="yes">
<test name="fi.foobar.FastTestSuite"/>
<formatter type="xml"/>
<classpath refid="test.classpath"/>
</junit>
...但到目前为止还没有运气。
编辑:除了 IDE,它还可以在命令行上与 JUnitCore 一起正常工作:
$ java -classpath "classes:WebContent/WEB-INF/lib/*" org.junit.runner.JUnitCore fi.foobar.FastTestSuite
.............
Time: 0.189
OK (13 tests)
【问题讨论】:
-
is name="..." 是 org/test/TestSuite 之类的路径还是在包注释 org.test.TestSuite 中?错误是什么?
-
@oers:后者;完全限定的类名。没有真正的错误消息,它只是......失败了。
unittest-fast: [junit] Running fi.foobar.FastTestSuite [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.053 sec [junit] Test fi.foobar.FastTestSuite FAILED -
将格式化程序更改为普通格式并将 printsummary 更改为 withOutAndErr 。这应该显示错误的原因。我认为那里有一个异常。您的设置绝对是执行套件的正确方式。
-
@oers,谢谢!实际上,即使没有“withOutAnderr”,错误也存在(我忘了我需要查看单独的报告文件):
Testcase: initializationError took 0.002 sec Caused an ERROR null at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.reflect.Constructor.newInstance(Constructor.java:513)Btw,正如我在问题上编辑的那样,这适用于 JUnitCore,这似乎令人鼓舞...... -
嗨。我有一个相关的问题。随时插话:stackoverflow.com/questions/15776718/…