我们正在开发一个大项目,许多交互模块和团队正在开发这些模块。我们用jenkins实现了CI,它执行定期和on-commit构建,运行junit测试,fitnesse测试和cobertura覆盖。
由于我们正在与如此多的组件进行交互,因此对于某些特定项目,我们实现了集成测试,这些测试会调出Spring上下文,并运行许多模拟应用程序流的重要部分的测试用例。这些是为了简单/方便而实现为Junit,放在src / test文件夹中,但是不单元测试。
我们的问题是某些组件构建需要很长时间才能运行,其中一个已确定的问题是长时间运行的集成测试运行两次,一次是在测试阶段,一次是在cobertura阶段(作为cobertura仪器类,然后再次运行测试)。这导致了一个问题:是否可以从cobertura执行中排除测试?
在pom中使用exclude或ignore cobertura config仅适用于src / java类,而不适用于测试类。我在cobertura插件文档中找不到任何内容。我正在尝试通过配置找到一种方法。我认为可以实现的唯一另一种方法是将这些测试移动到另一个没有启用cobertura插件的maven模块,并让该模块成为集成测试的主页。这样,父pom的构建将触发集成测试,但它不属于cobertura的范围。但如果可以通过配置来完成,那将更容易:)
提前致谢, JG
====更新和解决方案====
在kkamilpl的答案上建立了一点之后(再次感谢!)我能够在不改变目录结构中的任何内容的情况下包含和排除所需的测试。只有java风格的表达式,一旦你意识到在surefire插件设置中覆盖,你就可以设法运行“除了包之外的所有包”/“只有给定的包”:
<profiles>
<profile>
<id>unit-tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<testcase.include>**/*.class</testcase.include>
<testcase.exclude>**/integration/*.class</testcase.exclude>
</properties>
</profile>
<profile>
<id>integration-tests</id>
<properties>
<testcase.include>**/integration/*.class</testcase.include>
<testcase.exclude>**/dummyStringThatWontMatch/*.class</testcase.exclude>
</properties>
</profile>
</profiles>
我能够使用integration
目标和默认配置文件运行所有单元测试(即除test
测试文件夹的内容之外的所有内容),然后使用test
调用目标integration-tests
只运行集成测试的{{1}}配置文件。然后就是在jenkins中添加对新配置文件的调用作为新的顶级目标调用(它针对父pom),以便jenkins构建将运行集成测试,但只运行一次,而不是让它们重新运行当cobertura使用测试目标时。
答案 0 :(得分:2)
您始终可以使用maven个人资料:http://maven.apache.org/guides/introduction/introduction-to-profiles.html
将测试分开到不同的目录,例如:
testsType1
SomeTest1.java
SomeTest2.java
testsType2
OtherTest1.java
OtherTest2.java
接下来在pom中为每种测试类型定义适当的配置文件,例如:
<profile>
<id>testsType1</id>
<properties>
<testcase.include>%regex[.*/testsType1/.*[.]class]</testcase.include>
<testcase.exclude>%regex[.*/testsType2/.*[.]class]</testcase.exclude>
</properties>
</profile>
定义默认配置文件:
<activation>
<activeByDefault>true</activeByDefault>
</activation>
最后定义surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>>
<configuration>
<includes>
<include>${testcase.include}</include>
</includes>
<excludes>
<exclude>${testcase.exclude}</exclude>
</excludes>
</configuration>
</plugin>
要使用它,请致电
mvn test #to use default profile
mvn test -P profileName #to use defined profileName