Tli*_*ink 1 pmd maven maven-surefire-plugin
如何让 Maven/SureFire 生成 HTML 测试报告而不是 XML 测试报告?适用于 SureFire、PMD 和其他质量控制工具。
所以它看起来像这里的那些。
根据我们上面的对话,听起来您正在寻找一种多合一的 XML -> HTML 转换。我不知道这样的插件,但我相信万无一失的报告插件结合一两个其他插件会让你到达你需要的地方。
首先,我会查看surefire-report插件的使用文档。此外,我还提供了一个快速示例,说明如何通过组合 surefire、pmd 和 surefire 报告插件来开始:
使用以下项目结构:
??? pom.xml
??? src
??? main
? ??? java
? ? ??? Main.java
? ? ??? SomeClass.java
? ??? resources
??? test
??? java
??? SampleTest.java
Run Code Online (Sandbox Code Playgroud)
这些类定义:
类.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");
}
}
Run Code Online (Sandbox Code Playgroud)
示例测试.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);
}
}
Run Code Online (Sandbox Code Playgroud)
最后,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>
Run Code Online (Sandbox Code Playgroud)
结果是我跑的时候
mvn clean pmd:pmd site
Run Code Online (Sandbox Code Playgroud)
然后我可以打开生成的站点:
open target/site/index.html
Run Code Online (Sandbox Code Playgroud)
从那里,我可以看到我生成的报告,就我而言,只有 PMD 和 surefire 测试报告:

此外,如果您想获得更多可能 Surefire 报告插件无济于事的报告,请查看Jacoco,甚至可以查看 Sonar。
| 归档时间: |
|
| 查看次数: |
3342 次 |
| 最近记录: |