我想使用ant以编程方式创建junit报告。我在此之前已经看到过这个问题:Ant:create JUnit report task programmatically和此处:Creating JUnit report programmatically。我的代码差别不大,我不知道那些东西在哪里。 我的代码:
<?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"));
提前感谢您的帮助。
答案 0 :(得分: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");