What is Maven?
Maven is an open-source build automation and project management tool that helps developers build, publish, and deploy projects. It's written in Java and is primarily used for Java projects, but can also be used for projects written in other languages like C#, Ruby, and Scala. It is often used to run Java unit tests.
Enabling XML Output
When a Maven project is tested with mvn test
it does not automatically produce JUnit XML output. You can enable XML output with the Surefire plugin. To enable it, add the following to the plugins
section of your pom.xml
file. This process is the same whether you use test using JUnit or TestNG.
1<plugin>2 <groupId>org.apache.maven.plugins</groupId>3 <artifactId>maven-surefire-plugin</artifactId>4 <version>3.3.1</version>5</plugin>
and then run
1mvn test
The output will be in the target/surefire-reports
directory.
Test Suite naming
You can change the output filename with the <reportsDirectory>
property.
1<plugin>2 <groupId>org.apache.maven.plugins</groupId>3 <artifactId>maven-surefire-report-plugin</artifactId>4 <version>3.3.1</version>5 <configuration>6 <reportsDirectory>coolthing</reportsDirectory>7 </configuration>8</plugin>
You can see a full list of configuration options here.
Handling Retries
Maven can retry failed tests using a command line option.
1mvn -D surefire.rerunFailingTestsCount=2 test
See the Rerun Failing Tests page for more details.
Other Configuration
See an example of running Maven inside of a GitHub action here.