gpt4 book ai didi

java - ant junit 任务不报告详细信息

转载 作者:IT老高 更新时间:2023-10-28 20:33:03 25 4
gpt4 key购买 nike

我尝试用 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>目录

 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 结果/详细信息/报告?所以在我的真实失败案例中,我无法解决我的问题?

最佳答案

您必须在 junit 任务中使用 formatter 元素。默认情况下,格式化程序将创建一个报告文件,但您可以强制它在屏幕上打印结果。您可以使用两种格式化程序:一种用于输出到屏幕,另一种用于输出到文件。

请注意,您不再需要 junit 任务中的 printsummary="yes"showoutput="true" 属性。格式化程序现在负责输出。

<project name = "TestPrj" default="unittest" basedir = ".">

<target name="unittest" >
<junit>
<classpath>
<pathelement location="./junit-4.8.2.jar"/>
<pathelement location="./ant-junit4.jar"/>
</classpath>
<formatter type="plain" usefile="false" /> <!-- to screen -->
<formatter type="plain" /> <!-- to file -->
<test name = "com.mytest.unittest.SimpleTest" todir="."/>
</junit>
</target>

</project>

阅读 junit更多信息请参见 ant 手册。

关于java - ant junit 任务不报告详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5521311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com