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>
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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With