JUnitFormatter

Build StatusDocumentationDownloadsCoverage Status

A simple ExUnit Formatter that collects test results and generates an xml report in JUnit format. This is intended to be used by tools that can produce a graphical report, mainly targeted at Jenkins and its support for JUnit.

The report is generated in Mix.Project.app_path folder with a default filename of test-junit-report.xml. It can be configured through application configuration on the key report_file (application junit_formatter).

Versions 3+ require minimum Elixir version to be 1.5+. For older releases, please use version 2.2 of this library.

Usage

First, add JUnitFormatter to the dependencies in your mix.exs:

  defp deps do
    [
      {:junit_formatter, "~> 3.0", only: [:test]}
    ]
  end

Next, add JUnitFormatter to your ExUnit configuration in test/test_helper.exs file. It should look like this:

ExUnit.configure formatters: [JUnitFormatter]
ExUnit.start

If you want to keep using the default formatter alongside the JUnitFormatter your test/test_helper.exs file should look like this:

ExUnit.configure formatters: [JUnitFormatter, ExUnit.CLIFormatter]
ExUnit.start

Then run your tests like normal:

....

Finished in 0.1 seconds (0.07s on load, 0.08s on tests)
4 tests, 0 failures

Randomized with seed 600810

The JUnit style XML report for this project looks like this:

<?xml version="1.0"?>
<testsuites>
    <testsuite errors="0" failures="0" name="Elixir.FormatterTest" tests="4" time="82086">
        <testcase classname="Elixir.FormatterTest" name="test it counts raises as failures" time="16805"/>
        <testcase classname="Elixir.FormatterTest" name="test that an invalid test generates a proper report" time="16463"/>
        <testcase classname="Elixir.FormatterTest" name="test that a valid test generates a proper report" time="16328"/>
        <testcase classname="Elixir.FormatterTest" name="test valid and invalid tests generates a proper report" time="32490"/>
    </testsuite>
</testsuites>

note: this example has been reformatted for readability.

Options

JUnitFormatter accepts 4 options that can be passed in config.exs (or equivalent environment configuration for tests):

Example configuration:

config :junit_formatter,
  report_file: "report_file_test.xml",
  report_dir: "/tmp",
  print_report_file: true,
  prepend_project_name?: true

This would generate the report at: /tmp/myapp-report_file_test.xml.

Umbrella projects

JUnitFormatter works with umbrella projects too. By default, it will generate the xml report on each sub-project build folder. So, as an example, if you have two apps (my-app and another) it will generate the following reports:

This works without any extra configuration. There are times, though, where you want to customize the directory where the reports are generated. Let's say you add this configuration:

config :junit_formatter,
  report_dir: "/tmp"

Then, while running in an umbrela project, the first sub-project will run and generate a report file the following path:

The next one will do the same OVERRIDING the first one. So, in order to avoid this, you can use the configuration option prepend_project_name? so that the result would be:

LICENSE

This project is available under Apache Public License version 2.0. See LICENSE.