Steven De Groote
Steven De Groote

Reputation: 2233

Running junit ant-task without build.xml

I'm trying to work out how I can run an ant task without actually needed a build.xml. In particular I want to run a JUnit task with a formatter. In xml format this looks like below:

<junit printsummary="true" errorProperty="test.failed" failureProperty="test.failed">
    <classpath refid="run.class.path" />

    <!-- console log -->
    <formatter type="xml" classname="be.x.SFFormatter" />

    <test name="be.x.SF" outfile="result" todir="${build.output.dir}" />
</junit>

It works when running the ant script, but I would like to get my app running as a runnable jar. Running the tests from Java was easy:

    JUnitCore junit = new JUnitCore();
    testResult = junit.run(SeleniumFramework.class);

However, I struggle to work out how to actually get the formatter to work. The formatter is of type org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter so I doubt I can just plug it in somewhere without running ant.

Has anyone done something similar before? Thanks!

Upvotes: 0

Views: 335

Answers (2)

Rebse
Rebse

Reputation: 10377

You may use Ant via Groovy to avoid the xml syntax.
See => Using Ant from Groovy for details.

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328724

Ant doesn't do any magic. All it does is read the XML file, create the beans specified in it and then execute the methods as per the Task API (org.apache.tools.ant.Task).

So all you need is to do the same in your code. Don't forget to create a Project :-)

Upvotes: 2

Related Questions