运行“安装”时如何避免再次运行“测试”

在我们的Maven项目中,我们有两个目标:cleantestinstall

如果我运行mvn clean install,它将运行test,这是install的前提。如果我随后再次运行mvn clean install而没有任何代码更改,它将再次运行test

如何使其足够聪明,以避免第二次不必要地运行test

lhsstar 回答:运行“安装”时如何避免再次运行“测试”

您可以利用两个有用的属性来操纵测试用例

# Skip test cases compilation
mvn -Dmaven.test.skip install

# Compile test cases but not execute them
mvn -DskipTests install

但是,如果您希望maven仅运行已更改的测试,则不能这样做。这是Gradle在Maven上提供的非常方便的事情之一。

您可以浏览此站点: https://dzone.com/articles/reducing-test-times-only 这个人创建了poc的地方,尽管这是一种变通方法(maven未提供),所以我认为您需要为案例提供Gradle聪明的东西。

,

这会跳过测试

mvn clean install -Dmaven.test.skip=true
,

clean之外,每个Maven阶段都运行生命周期的每个进行中的Maven阶段。即test运行验证,编译和测试。

因此,由于install 已经已经运行了每个处理阶段,包括test,因此不必费心调用mvn test。如果测试失败,它将不会继续进行。

tl; dr:您想要的是

mvn clean install
,

您可以通过参数告诉Maven包含/排除测试:

# Exclude one test class,by using the explanation mark (!)
mvn clean install -Dtest=!LegacyTest
# Exclude one test method
mvn clean install -Dtest=!LegacyTest#testFoo
# Exclude two test methods
mvn clean install -Dtest=!LegacyTest#testFoo+testBar
# Exclude a package with a wildcard (*)
mvn clean install -Dtest=!com.mycompany.app.Legacy*

告诉maven包括特定测试:

# Include one file
mvn clean install -Dtest=AppTest
# Include one method
mvn clean install -Dtest=AppTest#testFoo
# Include two methods with the plus sign (+)
mvn clean install -Dtest=AppTest#testFoo+testBar
# Include multiple items comma separated and with a wildcard (*)
mvn clean install -Dtest=AppTest,Web*
# Include by Package with a wildcard (*)
mvn clean install -Dtest=com.mycompany.*.*Test

注意:我们可能需要转义“!”在使用bash时。

mvn clean install -Dtest=\!LegacyTest

要逃脱,我们必须使用反斜杠(\)

本文链接:https://www.f2er.com/3157783.html

大家都在问