[英]Conditional run of integration tests in maven
我的Java项目中有一个包含多个集成测试的模块。 其中两个是UpgradeDatabase.java和CreateDatabase.java,它们当前在集成前阶段的每次运行中都执行。 我想将它们安排为每隔一段时间(例如每月一次)运行,因为它们执行时间太长(创建了许多DB,等等),如何实现呢? 我的故障安全插件配置如下所示(请注意,skip.selenium.tests参数为false):
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<forkMode>${tests.forkMode}</forkMode>
<skip>${skip.selenium.tests}</skip>
<environmentVariables>
...this area skipped...as it's non important
</environmentVariables>
<systemPropertyVariables>
<!--<rc.count.firefox>${rc.count.firefox}</rc.count.firefox>-->
<selenium.browser>firefox</selenium.browser>
<user.home>${env.USERPROFILE}</user.home>
</systemPropertyVariables>
</configuration>
<executions>
<!--before the tests-->
<execution>
<id>upgrade-the-database</id>
<configuration>
<includes>
<include>**/UpgradeDatabase.java</include>
</includes>
</configuration>
<phase>pre-integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
<!--before the tests-->
<execution>
<id>recreate-the-database</id>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<includes>
<include>**/CreateDatabase.java</include>
</includes>
</configuration>
<phase>pre-integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
看看Build Profiles 。
简而言之。 用以下命令封装您的配置:
<profiles>
<profile>
<id>monthly</id>
... your configuration ...
</profile>
</profiles>
如果要默认将其激活,请将其添加到settings.xml
:
<activeProfiles>
<activeProfile>monthly</activeProfile>
</activeProfiles>
或在cmd行上将其激活:
mvn -P monthly ...
如果您使用的是TestNG,建议您通过测试组进行处理。
您可以为每个测试指定该测试所属的组(例如@Test(groups = { "SlowIntegrationTest" })
)。 与运行Maven相比,您可以指定应执行的组(例如, clean test -Dgroups=UnitTest,IntegrationTest
)。
当然,这涉及开发人员的纪律以正确标记测试。 但是,如果有人忘记标记测试,则不会执行该测试,并且应该在特定模块的覆盖率统计中列出(这取决于CI流程的质量)。
@misha对您先前的回答发表评论:
纯粹的外部Maven配置文件激活:
例如,使用参数PROFILE设置常规构建作业的参数 ,并使用默认的空参数值(如果不支持空值,则仅使用空格字符)。 将此参数添加到您的mvn cmd行:
mvn $ {PROFILE} ...
这样,一个空(或空格)值被添加到您的cmd行,什么也没做。
创建一个每月构建作业,该作业将触发常规构建,并使用-P month值注入此参数,以便常规构建的cmd行变为:
mvn -P每月...
外部和POM内部Maven配置文件混合激活:
见5.3。 配置文件激活或构建配置文件简介,有关配置文件激活的详细信息 。
在您的个人资料中添加一个激活部分,例如:
<活化>\n <属性>\n <名称>每月</名称>\n </属性>\n </激活>
...并为您的常规版本的mvn cmd行提供适当的属性:
mvn -D每月...
...例如,使用上述1.的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.