代码地址
https://gitee.com/bzrj/thresh-boot
如何使用
- 在
thresh-dependencies
目录执行mvn clean install
- 在跟目录执行
make
效果
jacoco
allure
关键配置
thresh-test
- 此模块包含了测试需要的依赖
- 定义了两个 testng 监听
thresh-report
此模块专门用于聚合 jacoco 和 allure 的报告
<?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><parent><groupId>com.laolang.thresh</groupId><artifactId>thresh-boot</artifactId><version>${revision}</version></parent><artifactId>thresh-report</artifactId><dependencies><dependency><groupId>com.laolang.thresh</groupId><artifactId>thresh-module-system-biz</artifactId></dependency><dependency><groupId>com.laolang.thresh</groupId><artifactId>thresh-module-auth-biz</artifactId></dependency></dependencies><build><plugins><!-- 生成聚合报告 --><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><executions><execution><id>prepare-agent</id><goals><goal>prepare-agent</goal></goals></execution><execution><id>report</id><phase>test</phase><goals><goal>report-aggregate</goal></goals></execution></executions></plugin></plugins></build>
</project>
模块 pom
注意:
由于使用了 powermock , 所以需要使用 jacoco 的 offline 模式
<build><plugins><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>${jacoco-maven-plugin.version}</version><executions><execution><id>default-instrument</id><goals><goal>instrument</goal></goals></execution><execution><id>default-restore-instrumented-classes</id><goals><goal>restore-instrumented-classes</goal></goals></execution><execution><id>pre-test</id><goals><goal>prepare-agent</goal></goals></execution><execution><id>post-test</id><phase>prepare-package</phase><goals><goal>report</goal></goals><configuration><dataFile>${project.build.directory}/jacoco.exec</dataFile></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${maven-surefire-plugin.version}</version><configuration><argLine>-Dfile.encoding=UTF-8-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine><testFailureIgnore>true</testFailureIgnore><systemPropertyVariables><jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile></systemPropertyVariables><!--生成allure-result的目录--><systemProperties><!--是否忽略html,解释见下图。与之后在reportNg报告上显示截图相关。当前已经使用allure了,这里可以直接去掉啦--><!--<org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output>--><!--定义输出在项目 target 目录--><property><name>allure.results.directory</name><value>target/allure-results</value></property></systemProperties><suiteXmlFiles><!--该文件位于工程根目录时,直接填写名字,其它位置要加上路径--><suiteXmlFile>${xmlFileName}</suiteXmlFile></suiteXmlFiles></configuration></plugin></plugins></build>
根目录
用于配置插件依赖
<build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${maven.compiler.source}</source><target>${maven.compiler.target}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins><pluginManagement><plugins><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>${jacoco-maven-plugin.version}</version></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${maven-surefire-plugin.version}</version></plugin></plugins></pluginManagement></build>