How can I run Perl tests and combine results with JUnit reports in Ant?

I would like to run Perl tests under Ant and produce XML output in a format similar to that created by Ant JUnit task .

I understand that the formats TAP :: Formatter :: JUnit and TAP :: Harness :: JUnit exist, but since I have no experience in Perl, I don’t know where to start.

+4
source share
2 answers

If you already have tests using Test::More or the like, using prove --formatter TAP::Formatter::JUnit is the easiest way. You do not change any of your tests or Perl code, and you get JUnit output that uses Java tools.

We use this setting with Hudson so that we can track our tests and get good error reports if necessary from the built-in Hudson tools without a lot of distortion. Our build is based on make , but this is the only real difference from your installation.

This means that you should be able to run prove as an external task and get benefits without having to significantly change the Ant tool if this is not clear.

Depending on which Perl you installed, you may or may not have prove . Run

 perl -MTest::Harness -e'print "$Test::Harness::VERSION\n"' 

to find out which version you have is 3.00 or better, prove ; Ideally, you should install 3.23 to get the best functionality:

 sudo cpan Test::Harness TAP::Formatter::JUnit 

This installs the latest version of Test :: Harness, TAP :: Formatter :: JUnit and all the necessary prerequisites. Try an external process with

 prove --formatter TAP::Formatter::JUnit your/testsuite/directory/ 

You should get the JUnit XML file at the end of the prove run. If all this works, add it to Ant with

 <target name="run"> <exec executable="prove"> <arg value="--formatter" /> <arg value="TAP::Formatter::JUnit" /> <arg path="your/testsuite/directory/" /> </exec> 

Ant documentation for "Exec"

(I believe that this is the correct Ant syntax for running an external program, but I am not an Ant expert).

+5
source

An alternative to TAP::Formatter::JUnit is TAP::Harness::JUnit . For instance:

prove --harness TAP::Harness::JUnit t

I found that TAP::Formatter::JUnit not installed on Windows, while TAP::Harness::JUnit seems to work everywhere.

0
source

All Articles