Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create junit report programmatically

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.

like image 589
user1189571 Avatar asked Jan 15 '23 18:01

user1189571


1 Answers

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");
like image 124
gontard Avatar answered Jan 22 '23 07:01

gontard