ant junit 任务不报告详细信息 [英] ant junit task does not report detail

查看:26
本文介绍了ant junit 任务不报告详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用 JUnit 测试写一个蚂蚁,但得到以下结果:

单元测试:[junit] 运行 com.mytest.utiltest[junit] 测试运行:1,失败:0,错误:1,经过的时间:0 秒[junit] 测试 com.mytest.utiltest 失败

它只显示没有打印细节的错误,我在 build.xml 中指定了以下参数还尝试从 ant -v 或 ant -debug 开始,但没有任何运气.有人可以帮忙吗?

ant 1.8.2,sun jdk1.6.0_20,junit 4.8.2

为了缩小问题的范围,我创建了一个单独的项目这是我的 build.xml

<目标名称=单元测试"><junit printsummary="yes" showoutput="true" ><类路径><pathelement location="./junit-4.8.2.jar"/><pathelement location="./ant-junit4.jar"/></classpath><测试名称 = "com.mytest.unittest.SimpleTest" todir="."/></junit></目标></项目>

下面是 simpletest.java

package com.mytest.unittest;导入 junit.framework.TestCase;公共类 SimpleTest 扩展了 TestCase{公共无效 testFirst(){断言真(真);}}

C:\TestPrj>ant

构建文件:C:\TestPrj\build.xml单元测试:[junit] 运行 com.mytest.unittest.SimpleTest[junit] 测试运行:1,失败:0,错误:0,经过的时间:0 秒建造成功总时间:0秒

C:\TestPrj>目录

 C:\TestPrj 目录04/02/2011 02:00 PM <DIR>.04/02/2011 02:00 PM <DIR>..04/02/2011 01:56 PM 280 .classpath04/02/2011 01:54 PM 519 .project04/02/2011 02:00 PM 7,120 ant-junit4.jar04/02/2011 02:00 PM 403 build.xml04/02/2011 01:55 PM <DIR>电脑11/17/2010 05:36 PM 237,344 junit-4.8.2.jar5 个文件 245,666 字节3 目录 28,451,311,616 字节空闲

为什么没有生成 JUnit 结果/详细信息/报告?所以在我的实际失败案例中,我无法解决我的问题?

解决方案

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

请注意,junit 任务中不再需要属性 printsummary="yes"showoutput="true".格式化程序现在正在处理输出.

<目标名称=单元测试"><junit><类路径><pathelement location="./junit-4.8.2.jar"/><pathelement location="./ant-junit4.jar"/></classpath><formatter type="plain" usefile="false"/><!-- 到屏幕--><formatter type="plain"/><!-- 到文件--><测试名称 = "com.mytest.unittest.SimpleTest" todir="."/></junit></目标></项目>

阅读 ant 手册中的 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?

解决方案

You have to use a formatter element inside the junit 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" and showoutput="true" in the junit task. The formatter is taking care of output now.

<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>

Read the junit page in the ant manual for more information.

这篇关于ant junit 任务不报告详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆