ant junit任务不报告详细信息
我尝试用 JUnit 测试编写一个 ant,但得到以下结果:
unittest:
[junit] Running com.mytest.utiltest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test com.mytest.utiltest FAILED
它只显示错误,没有打印详细信息,我在 build.xml 中指定以下参数 还尝试从 ant -v 或 ant -debug 开始,但没有得到任何运气。有人可以帮忙吗?
<junit printsummary="yes" showoutput="true">
ant 1.8.2,sun jdk1.6.0_20,junit 4.8.2
为了缩小问题范围,我创建了一个单独的项目 这是我的 build.xml
<project name = "TestPrj" default="unittest" basedir = ".">
<target name="unittest" >
<junit printsummary="yes" showoutput="true" >
<classpath>
<pathelement location="./junit-4.8.2.jar"/>
<pathelement location="./ant-junit4.jar"/>
</classpath>
<test name = "com.mytest.unittest.SimpleTest" todir="."/>
</junit>
</target>
</project>
,下面是 simpletest.java
package com.mytest.unittest;
import junit.framework.TestCase;
public class SimpleTest extends TestCase{
public void testFirst()
{
assertTrue(true);
}
}
C:\TestPrj>ant
Buildfile: C:\TestPrj\build.xml
unittest:
[junit] Running com.mytest.unittest.SimpleTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec
BUILD SUCCESSFUL
Total time: 0 seconds
C:\TestPrj>dir
Directory of C:\TestPrj
04/02/2011 02:00 PM <DIR> .
04/02/2011 02:00 PM <DIR> ..
04/02/2011 01:56 PM 280 .classpath
04/02/2011 01:54 PM 519 .project
04/02/2011 02:00 PM 7,120 ant-junit4.jar
04/02/2011 02:00 PM 403 build.xml
04/02/2011 01:55 PM <DIR> com
11/17/2010 05:36 PM 237,344 junit-4.8.2.jar
5 File(s) 245,666 bytes
3 Dir(s) 28,451,311,616 bytes free
为什么没有生成 JUnit 结果/详细信息/报告? 那么在我真实的失败案例中,我无法解决我的问题吗?
I tried to write an ant with JUnit test, but get below result:
unittest:
[junit] Running com.mytest.utiltest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test com.mytest.utiltest FAILED
it just shows error without print details, I specify below parameter in build.xml
also tried to start with ant -v or ant -debug
, but did not get any luck. Can anyone help?
<junit printsummary="yes" showoutput="true">
ant 1.8.2, sun jdk1.6.0_20, junit 4.8.2
to narrow down the problem, I created a seperate project
this is my build.xml
<project name = "TestPrj" default="unittest" basedir = ".">
<target name="unittest" >
<junit printsummary="yes" showoutput="true" >
<classpath>
<pathelement location="./junit-4.8.2.jar"/>
<pathelement location="./ant-junit4.jar"/>
</classpath>
<test name = "com.mytest.unittest.SimpleTest" todir="."/>
</junit>
</target>
</project>
below is simpletest.java
package com.mytest.unittest;
import junit.framework.TestCase;
public class SimpleTest extends TestCase{
public void testFirst()
{
assertTrue(true);
}
}
C:\TestPrj>ant
Buildfile: C:\TestPrj\build.xml
unittest:
[junit] Running com.mytest.unittest.SimpleTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0 sec
BUILD SUCCESSFUL
Total time: 0 seconds
C:\TestPrj>dir
Directory of C:\TestPrj
04/02/2011 02:00 PM <DIR> .
04/02/2011 02:00 PM <DIR> ..
04/02/2011 01:56 PM 280 .classpath
04/02/2011 01:54 PM 519 .project
04/02/2011 02:00 PM 7,120 ant-junit4.jar
04/02/2011 02:00 PM 403 build.xml
04/02/2011 01:55 PM <DIR> com
11/17/2010 05:36 PM 237,344 junit-4.8.2.jar
5 File(s) 245,666 bytes
3 Dir(s) 28,451,311,616 bytes free
Why there's not a JUnit results/detail/report generated?
So that in my real case of failure, i can not troubleshoot my questions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在
junit
任务中使用formatter
元素。默认情况下,格式化程序将创建一个报告文件,但您可以强制它在屏幕上打印结果。您可以使用两种格式化程序:一种用于输出到屏幕,另一种用于输出到文件。请注意,您不再需要 junit 任务中的属性
printsummary="yes"
和showoutput="true"
。格式化程序现在正在处理输出。请阅读 ant 手册中的 junit 页面以获取更多信息。
You have to use a
formatter
element inside thejunit
task. The formatter will create a report file by default, but you can force it to print the results on screen. You can use two formatters: one for output to screen, another for output to file.Note that you no longer need the attributes
printsummary="yes"
andshowoutput="true"
in the junit task. The formatter is taking care of output now.Read the junit page in the ant manual for more information.
您可以在这里发布从 build.xml 调用 junit 的代码片段吗?构建失败的原因可能有多种。另外,请发布您要测试的测试用例。
编辑:您需要静态测试吗?
编辑:尝试使用参数 outfile
Could you post the snippet which calls junit from build.xml here? There can be several reasons why the build fails. Also, please post the testcase which you are trying to test.
EDIT: Do you need a static for a test?
EDIT: Try using the argument outfile