har*_*dsv 44
您可以-Dtest通过在前面添加!(感叹号)前缀来指定排除模式.例如,
mvn -Dtest=\!FlakyTest* install
Run Code Online (Sandbox Code Playgroud)
在这里找到并验证工作.例如,我能够通过使用以下方式跳过这个片状的Jenkins测试:
mvn -Dtest=\!CronTabTest* package
Run Code Online (Sandbox Code Playgroud)
Ste*_*eed 21
使用junit 4时,我想添加一个@Ignore注释.这对你有用,除非你有时只想忽略测试,或者只在构建从maven运行时忽略它.如果是这种情况,那么我会问"为什么?"
测试应该是一致的,它们应该是可移植的,并且它们应该总是通过.如果特定测试有问题,我会考虑重新编写,完全删除它,或将其移动到不同的测试套件或项目.
Nar*_*sim 10
如果您想使用 CLI 排除单个测试,您应该使用-Dtest和-Dit.test标志。
小心重置默认值。当您使用该!符号时,所有默认值都将被删除,您应该将它们放回原处。对于surefire您执行的普通测试,您应该添加*Test, Test*, *Tests, *TestCase,而对于failsafe您执行的集成测试,您应该添加IT*, *IT, *ITCase.
您可以在此处找到更多信息https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html(正常测试)
在这里https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html(集成测试)
-Dit.test='!ITsometestIT, IT*, *IT, *ITCase'
一个完整的mvn命令可能是这样的:
mvn -e -B -Dtest='!unitTestABC, *Test, Test*, *Tests, *TestCase' -Dit.test='!ITintegrationTestABCIT, IT*, *IT, *ITCase' -DfailIfNoTests=false clean install
记住使用'而不是"。使用双引号时,其中的任何!内容都将由bash.
还请记住,集成测试在mvn test. 与mvn verify只集成测试将运行,而不是单元测试
通常需要排除集成测试,但需要包含单元测试.为了实现这一点,我建议使用后缀IntegrationTest(例如AbcIntegrationTest.java)命名所有集成测试.
然后在你的maven构建中提出以下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当您使用此构建时,将排除所有集成测试,但运行所有其他测试(例如,单元测试).完美:-)
有关排除和测试运行期间测试的更多信息,请阅读
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
PS要排除单个测试,您只需在排除列表中明确命名.简单.
使用注释查看此解决方案@Category
public class AccountTest {
@Test
@Category(IntegrationTests.class)
public void thisTestWillTakeSomeTime() {
...
}
@Test
@Category(IntegrationTests.class)
public void thisTestWillTakeEvenLonger() {
...
}
@Test
public void thisOneIsRealFast() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用测试套件运行:
@RunWith(Categories.class)
@IncludeCategory(SlowTests.class)
@SuiteClasses( { AccountTest.class, ClientTest.class })
public class LongRunningTestSuite {}
Run Code Online (Sandbox Code Playgroud)
我认为如果使用这个命令应该可以工作:
mvn archetype:create -DgroupId=test -DartifactId=test
Run Code Online (Sandbox Code Playgroud)
(为了测试,将 pom.xml 和 test-class 更改为以下内容并使用 mvn install)
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>test</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>
test/AppTest.java
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
测试类:
package test;
import org.junit.Test;
import static org.junit.Assert.fail;
public class AppTest
{
@Test
public void test_it() {
fail("not implemented");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37766 次 |
| 最近记录: |