gpt4 book ai didi

maven - 使用 Maven Surefire 运行嵌套的 JUnit 5 测试

转载 作者:行者123 更新时间:2023-12-03 14:43:55 26 4
gpt4 key购买 nike

在迁移我的主项目之前,我试图在我的副项目中使用 JUnit 5 作为试验。我想使用 @Nested 测试使我的测试类更干净。
当我整体运行我的测试套件时,一切都很好。但是,只要我尝试只运行一个测试,就不会执行 @Nested 测试。

mvn -Dtest=com.mycompany.test.MyTest surefire:test

有没有办法让它运行选定的类和所有@Nested 类?

使用 JUnit 5.1.0,JUnit 平台 1.1.0
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${org.junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${org.junit.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

测试类:
public class MyTest {

@Test
public void thisTestExecutes() { }

@Nested
public class NestedTests {
@Test
public void thisTestDoesnt() { }
}
}

最佳答案

要运行所有嵌套类,您只需要在类名末尾添加一个“*”。就像是:

mvn -Dtest=com.mycompany.test.MyTest\* surefire:test

关于maven - 使用 Maven Surefire 运行嵌套的 JUnit 5 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49453319/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com