创建JUnit报告编程 [英] Create junit report programmatically

查看:174
本文介绍了创建JUnit报告编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式创建JUnit报告使用蚂蚁。我已经看到了这个问题已经来过这里问:<一href=\"http://stackoverflow.com/questions/3916717/antcreate-junit-report-task-programmatically\">Ant:create JUnit的报告任务编程并在这里:创建JUnit报告编程的。我的code是有点不同,我不知道所有的东西去。
我的code:

I would like to create junit report programmatically using ant. I've seen that this question has been asked before here: Ant:create JUnit report task programmatically and here: Creating JUnit report programmatically. My code is little different and I don't know where all that stuff goes. My code:

<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" default="junitreport" basedir=".">
    <target name="junitreport">
        <junitreport todir="./testreport">
            <fileset dir="./junitreports">
                <include name="*.xml"/>
            </fileset>
            <report format="noframes" todir="./testreport"/>
        </junitreport>
    </target>
</project>

来源$ C ​​$ C:

Source code :

FileSet fs = new FileSet();
fs.setDir(new File("./junitreports"));
fs.createInclude().setName("*.xml");
XMLResultAggregator aggregator = new XMLResultAggregator();
aggregator.addFileSet(fs);
AggregateTransformer transformer = aggregator.createReport();
transformer.setTodir(new File("./testreport"));

在此先感谢您的帮助。

Thanks in advance for your help.

推荐答案

您已经配置了junitreport蚂蚁的任务,但你也应该执行它。

You have configured the junitreport ant task but you should also execute it.

Project project = new Project();
project.setName("myproject");
project.init();

Target target = new Target();
target.setName("junitreport");
project.addTarget(target);

FileSet fs = new FileSet();
fs.setDir(new File("./junitreports"));
fs.createInclude().setName("*.xml");
XMLResultAggregator aggregator = new XMLResultAggregator();
aggregator.setProject(project);
aggregator.addFileSet(fs);
AggregateTransformer transformer = aggregator.createReport();
transformer.setTodir(new File("./testreport"));

target.addTask(aggregator);
project.executeTarget("junitreport");

这篇关于创建JUnit报告编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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