Jenkins集成Cucumber生成图形化的测试报告
1、配置项目pom文件将Cucumber的启动类配置到pom文件中,在Jenkins构建的时候,会跑Cucumber的测试类,配置如下:[html]view plaincopyprint?profiles> profile> id>cucumberid> build>
·
1、配置项目pom文件
将Cucumber的启动类配置到pom文件中,在Jenkins构建的时候,会跑Cucumber的测试类,配置如下:
- <profiles>
- <profile>
- <id>cucumber</id>
- <!-- 仅运行cucumber测试 -->
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <disableXmlReport>true</disableXmlReport>
- <includes>
- <include>**/cucumber启动类.java</include>
- </includes>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.10</version>
- <executions>
- <execution>
- <id>复制测试时用到的工具</id><!-- 由于我的测试中使用了aop,所以需要加这个配置 -->
- <phase>process-resources</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjweaver</artifactId>
- <version>1.8.5</version>
- </artifactItem>
- </artifactItems>
- <stripVersion>true</stripVersion>
- </configuration>
- </execution>
- <execution>
- <id>获得jar在m2中的路径,供plugin引用</id>
- <goals>
- <goal>properties</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.17</version>
- </plugin>
- <plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <version>0.7.4.201502262128</version>
- <!-- 要和sonar里面的保持一致 -->
- </plugin>
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <versionRange>[2.0,)</versionRange>
- <goals>
- <goal>copy-dependencies</goal>
- <goal>unpack</goal>
- <goal>copy</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore />
- </action>
- </pluginExecution>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.assertj</groupId>
- <artifactId>
- assertj-assertions-generator-maven-plugin
- </artifactId>
- <versionRange>
- [1.6.0,)
- </versionRange>
- <goals>
- <goal>
- generate-assertions
- </goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.jacoco</groupId>
- <artifactId>
- jacoco-maven-plugin
- </artifactId>
- <versionRange>
- [0.7.4.201502262128,)
- </versionRange>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- </profile>
- </profiles>
<profiles>
<profile>
<id>cucumber</id>
<!-- 仅运行cucumber测试 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<disableXmlReport>true</disableXmlReport>
<includes>
<include>**/cucumber启动类.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>复制测试时用到的工具</id><!-- 由于我的测试中使用了aop,所以需要加这个配置 -->
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.5</version>
</artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
</configuration>
</execution>
<execution>
<id>获得jar在m2中的路径,供plugin引用</id>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
<!-- 要和sonar里面的保持一致 -->
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
<goal>unpack</goal>
<goal>copy</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.assertj</groupId>
<artifactId>
assertj-assertions-generator-maven-plugin
</artifactId>
<versionRange>
[1.6.0,)
</versionRange>
<goals>
<goal>
generate-assertions
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jacoco</groupId>
<artifactId>
jacoco-maven-plugin
</artifactId>
<versionRange>
[0.7.4.201502262128,)
</versionRange>
<goals>
<goal>prepare-agent</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
注意cucumber启动类.Java,这个java类的作用是指定features文件的位置,步骤定义的位置,以及生成的测试报告存放的问题,该类代码如下:
- @RunWith(Cucumber.class)
- @CucumberOptions(plugin={"pretty", "html:target/cucumber", "json:target/cucumber.json", "junit:target/junit"},glue={"com.cucumber"}, features={"src/test/resources/features/"})
- public class cucumber启动类 {
- public static void main(String[] args) throws IOException {
- Main.run(args, Thread.currentThread().getContextClassLoader());
- }
- }
@RunWith(Cucumber.class)
@CucumberOptions(plugin={"pretty", "html:target/cucumber", "json:target/cucumber.json", "junit:target/junit"},glue={"com.cucumber"}, features={"src/test/resources/features/"})
public class cucumber启动类 {
public static void main(String[] args) throws IOException {
Main.run(args, Thread.currentThread().getContextClassLoader());
}
}
- 注:plugin选项用来指定生成的报告格式,多种格式用逗号隔开,glue用来指定cucumber的步骤定义位置,features用来指定features文件的位置
注:plugin选项用来指定生成的报告格式,多种格式用逗号隔开,glue用来指定cucumber的步骤定义位置,features用来指定features文件的位置
2、添加测试构建插件配置
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>javancss-maven-plugin</artifactId>
- <version>2.1</version>
- <configuration>
- <failOnViolation>true</failOnViolation>
- <lineThreshold>10000</lineThreshold>
- <ccnLimit>12</ccnLimit>
- <ncssLimit>90</ncssLimit>
- <includes>
- <include>**/*.java</include>
- </includes>
- <excludes>
- <exclude>**/bar.java</exclude>
- <exclude>**/foobar.java</exclude>
- </excludes>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <executions>
- <execution>
- <id>run-cucumber</id>
- <goals>
- <goal>test</goal>
- </goals>
- <phase>test</phase>
- <configuration>
- <disableXmlReport>false</disableXmlReport>
- <includes>
- <include>**/cucumber启动类.java</include>
- </includes>
- </configuration>
- </execution>
- </executions>
- <configuration>
- <testFailureIgnore>
- true<!-- 因为要执行Cucumber -->
- </testFailureIgnore>
- </configuration>
- </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javancss-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<failOnViolation>true</failOnViolation>
<lineThreshold>10000</lineThreshold>
<ccnLimit>12</ccnLimit>
<ncssLimit>90</ncssLimit>
<includes>
<include>**/*.java</include>
</includes>
<excludes>
<exclude>**/bar.java</exclude>
<exclude>**/foobar.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>run-cucumber</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<disableXmlReport>false</disableXmlReport>
<includes>
<include>**/cucumber启动类.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<testFailureIgnore>
true<!-- 因为要执行Cucumber -->
</testFailureIgnore>
</configuration>
</plugin>
3、在Jenkins中安装cucumber插件
需要安装的插件如下:
4、新建一个Jenkins项目,并配置
配置如下:
5、点击应用保存,并构建
6、构建完成后,效果如下
构建完之后,会多生成这两个链接,点击Cucumber Reports后就可以看到好看的测试报告了,下面是部分截图:
更多推荐
已为社区贡献2条内容
所有评论(0)