4

我想使用 ant 以编程方式创建 junit 报告。我已经看到之前在这里提出过这个问题:Ant:以编程方式创建 JUnit 报告任务,在这里:以编程方式创建 JUnit 报告。我的代码有点不同,我不知道所有这些东西都去哪里了。我的代码:

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

源代码 :

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"));

在此先感谢您的帮助。

4

1 回答 1

9

您已经配置了 junitreport ant 任务,但您也应该执行它。

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");
于 2012-08-21T20:49:25.613 回答