maven的goal生命周期
Maven生存周期 - 含 integration-test
Maven本身支持的命令(Goals)是有顺序的,越后面执行的命令,会将其前面的命令和其本身按顺序执行一遍,具体的顺序如下所示:
validate
initialize
generate-sources
process-sources
generate-resources
process-resources
compile
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources
test-compile
process-test-classes
test
prepare-package
package
pre-integration-test
integration-test
post-integration-test
verify
install
从上面maven的生存期可以看出
作者:哈比猪
链接:https://www.jianshu.com/p/e638d64b6955/
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
maven单元测试与集成测试
- 通过maven的Profile
- 配置生命周期 通过maven-surefire-plugin的生命周期配置不同的测试范围
如下使用的是方式2
unit包中包含的是单元测试
integration包种包含的是集成测试
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>run-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/integration/**/*.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>run-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/unit/**/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<dependentWarExcludes>WEB-INF/lib</dependentWarExcludes>
</configuration>
</plugin>
</plugins>
maven-failsafe-plugin 配置POM.XML
实际上POM.XML提供了很强大的配置功能,这里利用一个maven的插件,叫maven-failsafe-plugin,具体配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
这里创建了一个execution,当执行integration-test goal的时候,执行包括“IT.java”结尾的所有java文件,那如何跳过unit test,integration-test呢?看下面利用了另外一个插件,叫maven-surefire-plugin,如下配置:文章来源:https://www.toymoban.com/news/detail-618520.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
通过skip标签来指定跳过test的行为,默认是支持skipITs和skipTests,前者是跳过integration-test,后者是跳过所有的测试(稍微说明下,跳过测试方法有很多种,比如maven-failsafe-plugin本身也支持加入skip选项,只不过实现之后每个命令的含义就略微有不同了,大家选择自己最习惯的就好了).文章来源地址https://www.toymoban.com/news/detail-618520.html
-
推荐的测试目录结构
Unit Test Classes : src/test/java/**/**Test.java
Integration Test Classes : src/test/java/**/**IT.java
TestCases dependent files: src/test/resources/*
到了这里,关于集成测试,单元测试隔离 maven-surefire-plugin的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!