TAP::Harness::JUnit - Generate JUnit compatible output from TAP results


    use TAP::Harness::JUnit;
    my $harness = TAP::Harness::JUnit->new({
        xmlfile => 'output.xml',


The only difference between this module and TAP::Harness is that this adds optional 'xmlfile' argument, that causes the output to be formatted into XML in format similar to one that is produced by JUnit testing framework.


This modules inherits all functions from TAP::Harness.


These options are added (compared to TAP::Harness):


Name of the file XML output will be saved to. In case this argument is ommited, default of "junit_output.xml" is used and a warning is issued.

notimes (DEPRECATED)

If provided (and true), test case times will not be recorded.


Specify how to mangle testcase names. This is sometimes required to interact with buggy JUnit consumers that lack sufficient validation. Available values are:


Replace anything but alphanumeric characters with underscores. This is default for historic reasons.


Replace slashes in directory hierarchy with dots so that the filesystem layout resemble Java class hierarchy.

This is the recommended setting and may become a default in future.


Do not do any transformations.


JUnit XML schema was obtained from


This module was partly inspired by Michael Peters' TAP::Harness::Archive.

Following people (in no specific order) have reported problems or contributed fixes to TAP::Harness::JUnit:

David Ritter
Jeff Lavallee
Andreas Pohl


Test return value is ignored. This is actually not a bug, TAP::Parser doesn't present the fact and TAP specification does not require that anyway.

Note that this may be a problem when running Test::More tests with no_plan, since it will add a plan matching the number of tests actually run even in case the test dies. Do not do that -- always write a plan! In case it's not possible, pass merge argument when creating a TAP::Harness::JUnit instance, and the harness will detect such failures by matching certain comments.

Test durations are not mesaured. Unless the "notimes" parameter is provided (and true), the test duration is recorded as testcase duration divided by number of tests, otherwise it's set to 0 seconds. This could be addressed if the module was reimplmented as a formatter.

The comments that are above the ok or not ok are considered the output of the test. This, though being more logical, is against TAP specification.

XML::Simple is used to generate the output. It is suboptimal and involves some hacks.

During testing, the resulting files are not tested against the schema, which would be a good thing to do.


Lubomir Rintel (Good Data) <>

Source code for TAP::Harness::JUnit is kept in a public GIT repository. Visit to get it.


Copyright 2008, 2009 Good Data, All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.