Reputation: 913
How to get Maven/SureFire to produce an HTML test reports instead of the XML one? for SureFire, PMD and the rest of the Quality Control tools.
So it would look like the ones here.
Upvotes: 1
Views: 8250
Reputation: 2432
Based on our conversation above, it sounds like you are looking for an all in one XML -> HTML converted. I don't know of a plugin like that, but I believe the surefire report plugin combined with one or two others will get you where you need to be.
For starters, I would check out the usage docs for the surefire-report plugin. Additionally I threw together a quick example of how you can get started by combining the surefire, pmd, and surefire report plugin:
Using the following project structure:
├── pom.xml
└── src
├── main
│ ├── java
│ │ ├── Main.java
│ │ └── SomeClass.java
│ └── resources
└── test
└── java
└── SampleTest.java
And these class definitions:
SomeClass.java
import java.util.List; //Unused import, so PMD will have something to pick up
public class SomeClass {
public void testMethod(){
System.out.println("This is my test method with some PMD violations");
}
}
SampleTest.java
import org.junit.Assert;
import org.junit.Test;
//Sample tests, so the surefire report will have something to show
public class SampleTest {
@Test
public void test1(){
Assert.assertTrue(true);
}
@Test
public void test2(){
Assert.assertTrue(false);
}
}
and finally, pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sample</groupId>
<artifactId>plugins</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.9.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.21.0</version>
</plugin>
</plugins>
</reporting>
</project>
The result is that when I run
mvn clean pmd:pmd site
I can then open up the site that was generated:
open target/site/index.html
From there, I can see my generated reports, in my case, just PMD and surefire test reports:
Additionally, if you want to get more reports that maybe the surefire reporting plugin doesn't help with, check out Jacoco, and maybe even take a look into Sonar.
Upvotes: 5