Consuming eunit surefire xml reports.

Introduction

Eunit outputs test results on the command line, there is an eunit plugin to generate 'surefire' style xml output. This can be consumed by the 'surefire-reports' maven/mvn tool to generate HTML which might be a little bit more consumable for some people.

Basic configuration:

Edit rebar.config in your projects rebar.config and add the "eunit_opts" option as shown below.

{erl_opts, [debug_info]}.
{deps, []}.

%% add this line
{eunit_opts, [verbose, {report, {eunit_surefire, [{dir, "target/surefire-reports"}]}}]}.

{shell, [
    %% {config, "config/sys.config"},
    {apps, [surefire_demo]}
]}.

When you run eunit tests (In this case, with 'rebar3 eunit' command), it should create the target/surefire-reports directory and create XML files, the exact count depending on your project structure and test structures.

At this point you have completed the 'erlang' side of the test tooling. The next step is to configure the 'maven/java' tooling.

Create a pom.xml file in the projects root directory.

You should modify the ProjectName, url and version to match your tooling:

<project>
        <modelVersion>4.0.0</modelVersion>
        <groupId> 1 </groupId>
        <artifactId>ProjectName</artifactId>
        <version> 1 </version>
        <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
        <url>https://your-projects-url.com</url>
        <reporting>
                <plugins>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-project-info-reports-plugin</artifactId>
                                <version>3.1.2</version>
                                <!-- Replace with a suitable version -->
                        </plugin>
                </plugins>
        </reporting>
        <build>
                <plugins>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <version>3.5.4</version>
                                <configuration>
                                        <testFailureIgnore>true</testFailureIgnore>
                                        <linkXRef>false</linkXRef>
                                </configuration>
                        </plugin>
                        <!--
                            Convert .xml reports into .html report, but without the CSS or images.
                            equivalent: mvn surefire-report:report-only
                        -->
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-report-plugin</artifactId>
                                <version>3.5.4</version>
                                <executions>
                                        <execution>
                                                <phase>test</phase>
                                                <goals>
                                                        <goal>report-only</goal>
                                                </goals>
                                        </execution>
                                </executions>
                        </plugin>
                </plugins>
        </build>
</project>

A pom.xml file, or Project Object Model XML, is the configuration file for projects built with Apache Maven. Even though we build our project with erlang.

Install maven on your computer, apparently all java is cross platorm and super easy to install . If you're on a linux, you should use your package manager because it seems to work for me, on other platforms you may want to look into what best practices are, I couldnt' tell you.

From within the directory containing pom.xml you should run:

mvn surefire-report:report-only

This should generate a more complicated data structure.

$ surefire_demo tree target 
target
├── reports
│   ├── css
│   │   ├── apache-maven-fluido-2.0.0-M9.min.css
│   │   ├── print.css
│   │   └── site.css
│   ├── fonts
│   │   ├── glyphicons-halflings-regular.eot
│   │   ├── glyphicons-halflings-regular.svg
│   │   ├── glyphicons-halflings-regular.ttf
│   │   └── glyphicons-halflings-regular.woff
│   ├── images
│   │   ├── accessories-text-editor.png
│   │   ├── add.gif
│   │   ├── apache-maven-project-2.png
│   │   ├── application-certificate.png
│   │   ├── contact-new.png
│   │   ├── document-properties.png
│   │   ├── drive-harddisk.png
│   │   ├── fix.gif
│   │   ├── icon_error_sml.gif
│   │   ├── icon_help_sml.gif
│   │   ├── icon_info_sml.gif
│   │   ├── icon_success_sml.gif
│   │   ├── icon_warning_sml.gif
│   │   ├── image-x-generic.png
│   │   ├── internet-web-browser.png
│   │   ├── logos
│   │   │   ├── build-by-maven-black.png
│   │   │   ├── build-by-maven-white.png
│   │   │   └── maven-feather.png
│   │   ├── network-server.png
│   │   ├── package-x-generic.png
│   │   ├── profiles
│   │   │   ├── pre-release.png
│   │   │   ├── retired.png
│   │   │   └── sandbox.png
│   │   ├── remove.gif
│   │   ├── rss.png
│   │   ├── update.gif
│   │   └── window-new.png
│   ├── img
│   │   ├── glyphicons-halflings-white.png
│   │   └── glyphicons-halflings.png
│   ├── js
│   │   └── apache-maven-fluido-2.0.0-M9.min.js
│   └── surefire.html
└── surefire-reports
    ├── TEST-file_surefire_demo.app.xml
    └── TEST-some_test.xml

10 directories, 40 files

The html file to open in the browsers is ./target/reports/index.html . It requires the data directory structure as specified above, but the index.html could be renamed into a 'once off' like index-05-10-2025.html if you needed html records, If historical raw data is required, you could version the XML files.

Conclusion

The maven surefire reports tool is a simple way to generate html from eunit reports.

Resources: