最近领导让我找一个可以每次打包自动生成测试用例的东西,jenkins或者idea都可以,
最后找到了这个allure,也踩了很多坑,废话不多说!,总结一下:
1 使用原生allure
添加依赖:
<!-- 依赖reportNg 关联testNg--> <dependency> <groupId>org.uncommons</groupId> <artifactId>reportng</artifactId> <version>1.1.4</version> <scope>test</scope> <exclusions> <exclusion> <groupId>org.testng</groupId> <artifactId>testng</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>ru.yandex.qatools.allure</groupId> <artifactId>allure-testng-adaptor</artifactId> <version>1.3.6</version> <exclusions> <exclusion> <groupId>org.testng</groupId> <artifactId>testng</artifactId> </exclusion> </exclusions> </dependency> <!-- 依赖Guice --> <dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>4.0</version> </dependency> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-testng</artifactId> <version>2.0-BETA14</version> <scope>test</scope> </dependency>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> <configuration> <argLine> -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" </argLine> <!--生成allure-result的目录--> <systemProperties> <property> <name>allure.results.directory</name> <value>./target/allure-results</value> </property> </systemProperties> </configuration> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> </plugin>
这块配置生成目录一定要正确,最好在target下面,默认会是surefile-results目录,可自己查看
使用特定注解编写测试代码:
@Feature("前线突击测试") public class Test01 { @Test(description = "侯征测试") @Story("测试发券") @Description("主要测试四种券发送") @Step("测试步骤....") public void failedTest(){ Assert.assertEquals(2,2); } }
打包查看
项目根目录,使用命令:
mvn clean test
allure serve target/allure-results
会自动打开浏览器:
2 使用jenkins插件集成allure:
安装插件
配置allure
这里目录一定要和自己配置的目录一样,可先查看打包后在哪个目录,确保一定正确,不然用例报告没有数据
pom添加依赖
<!-- 依赖reportNg 关联testNg--> <dependency> <groupId>org.uncommons</groupId> <artifactId>reportng</artifactId> <version>1.1.4</version> <scope>test</scope> <exclusions> <exclusion> <groupId>org.testng</groupId> <artifactId>testng</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>ru.yandex.qatools.allure</groupId> <artifactId>allure-testng-adaptor</artifactId> <version>1.3.6</version> <exclusions> <exclusion> <groupId>org.testng</groupId> <artifactId>testng</artifactId> </exclusion> </exclusions> </dependency> <!-- 依赖Guice --> <dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>4.0</version> </dependency> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-testng</artifactId> <version>2.0-BETA14</version> <scope>test</scope> </dependency>
pom添加插件
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> <configuration> <argLine> -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" </argLine> <!--生成allure-result的目录--> <systemProperties> <property> <name>allure.results.directory</name> <value>./target/allure-results</value> </property> </systemProperties> </configuration> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> </plugin>
这里这个目录很重要,最好这里直接指定,不使用默认的.
编写代码
@Feature("前线突击测试") public class Test01 { @Test(description = "侯征测试") @Story("测试发券") @Description("主要测试四种券发送") @Step("测试步骤....") public void failedTest(){ Assert.assertEquals(2,2); } }
jenkins查看
注意点:生成内容为空问题(一般是路径不对):
我用的高版本,所以如果不写生成路径,默认是target/surefire-reports目录下,之前一直搞错了路径,所以一直有问题,
关于这个问题,如果为空,先去查看打包后的目录,看看生成的index.html这些在哪个目录,再看自己配置的对不对,
我就是被这个给坑了,网上说的都没有这一点,一定记住!