防止单元测试,但允许在Maven中进行集成测试 [英] Prevent unit tests but allow integration tests in Maven
问题描述
我有一个Maven构建,其中使用SureFire插件运行一些单元测试,并使用FailSafe插件运行一些集成测试.我想只运行FailSafe插件的测试.
在pom中添加不同的配置文件或其他内容对我来说不是一个好的解决方案,因为它是多模块构建,并且我不想编辑每个模块的pom.
有 我发现,仅跳过surefire测试的最简单方法是按以下方式配置surefire(但不设置故障安全性): 这允许您运行 请注意,这重新定义了用于指定应跳过测试的属性,因此,如果提供规范的 如果需要,可以为故障安全提供一个名为 这些 I've a Maven build in which I use the SureFire plugin to run some unit tests, and the FailSafe plugin to run some integration tests. I would like a way to run just the FailSafe plugin's tests. It's not a good solution for me to add different profiles or anything in the pom, because it's a multimodule build and I don't want to have to edit every module's pom. There are So, is there a command-line flag for Maven like I found the simplest way to skip only surefire tests is to configure surefire (but not failsafe) as follows: This allows you to run Note that this redefines the property used to specify that tests should be skipped, so if you supply the canonical If you need to, you could provide an analagous parameter called These 这篇关于防止单元测试,但允许在Maven中进行集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!skip.tests
和maven.test.skip
和skipTests
停止所有 测试,并且<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<!-- skips surefire tests without skipping failsafe tests.
Property value seems to magically default to false -->
<skipTests>${skip.surefire.tests}</skipTests>
</configuration>
</plugin>
mvn verify -Dskip.surefire.tests
,并且只跳过surefire(不是故障安全)测试;它还将运行所有其他必要阶段,包括集成前和集成后,并且还将运行verify
目标,如果集成测试失败,该目标实际上会使您的Maven构建失败.>
-DskipTests=true
,则surefire将忽略它,但故障保护将尊重它,这可能是意外的,特别是如果您已经有内部版本/用户已经指定了该标志.一个简单的解决方法似乎是将skip.surefire.tests
的默认值设置为pom的<properties>
部分中的skipTests
值:<properties>
<skip.surefire.tests>${skipTests}</skip.surefire.tests>
</properties>
skip.failsafe.tests
的类似参数,但是我没有必要这样做-因为单元测试通常在较早的阶段运行,并且如果我想运行单元测试而不是集成测试,我将运行test
阶段而不是verify
阶段.您的经历可能会有所不同!skip.(surefire|failsafe).tests
属性可能应该集成到surefire/failsafe代码本身中,但是我不确定它会违反它们是完全相同的插件,只是有一点点区别"的精神.skip.tests
and maven.test.skip
and skipTests
which stop all tests, and skipITs
, which stops only the failsafe plugin.skipITs
, but instead with the functionality of "onlyITs"?<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<!-- skips surefire tests without skipping failsafe tests.
Property value seems to magically default to false -->
<skipTests>${skip.surefire.tests}</skipTests>
</configuration>
</plugin>
mvn verify -Dskip.surefire.tests
and only surefire, not failsafe, tests will be skipped; it will also run all other necessary phases including pre-integration and post-integration, and will also run the verify
goal which is required to actually fail your maven build if your integration tests fail.-DskipTests=true
, surefire will ignore it but failsafe will respect it, which may be unexpected, especially if you have existing builds/users specifying that flag already. A simple workaround seems to be to default skip.surefire.tests
to the value of skipTests
in your <properties>
section of the pom:<properties>
<skip.surefire.tests>${skipTests}</skip.surefire.tests>
</properties>
skip.failsafe.tests
for failsafe, however I haven't found it necessary - because unit tests usually run in an earlier phase, and if I want to run unit tests but not integration tests, I would run the test
phase instead of the verify
phase. Your experiences may vary!skip.(surefire|failsafe).tests
properties should probably be integrated into surefire/failsafe code itself, but I'm not sure how much it would violate the "they're exactly the same plugin except for 1 tiny difference" ethos.