POM中配置的如下:
在通过mvn test执行了单元测试后,将会在工程的父级目录target/中生成surefire-reports子文件夹(包含.txt和.xml两种形式)
注意:如果不以上方的方式命名,不会生成报告;若引用的为Testng框架则不受此约束
其实以上都是为了在已配置的sonarqube平台中’代码覆盖率’作准备工作的,那么接下来最后执行如此即可:
mvn clean test cobertura:cobertura -Dcobertura.report.format=xml sonar:sonar
mvn clean test cobertura:cobertura -Dcobertura.report.format=xml sonar:sonar
附上一个Demo示例图

以上是本人花了两天时间总结而来的精华,翻阅了大量的网络资料。最后附上一个在实施完成之后的文章,个人推荐:http://seanzhou.iteye.com/blog/1393858
另外,Demo的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>SelfAnyTest</groupId><artifactId>SelfAnyTest</artifactId><version>0.0.1-SNAPSHOT</version><name>SelfAnyTest</name><description>非项目用的测试与调试工程</description><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency></dependencies><distributionManagement><snapshotRepository><id>ossrh</id><url>https://oss.sonatype.org/content/repositories/snapshots</url></snapshotRepository><repository><id>ossrh</id><url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement><build><resources><resource><directory>src/main/resources</directory></resource></resources><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>2.2.1</version></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>2.9.1</version></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.3</version><!-- <configuration><source>1.7</source><target>1.7</target><compilerId>eclipse</compilerId></configuration> --><dependencies><dependency><groupId>org.codehaus.plexus</groupId><artifactId>plexus-compiler-eclipse</artifactId><version>2.5</version></dependency></dependencies></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.19</version></plugin></plugins></build></project>
因为maven有很多依赖可以非显示的写入,具体的受限于精力及非服务需要,未作探究。
