我想在 Maven 项目中使用 Junit 5:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
我当前想禁用测试:
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;
@Disabled
public class DatabaseFeaturesBitStringTest {
....
}
但这不起作用。测试在 mvn clean build 之后执行。你能告诉我我错过了什么吗?
这是由于之间不兼容造成的maven-surefire-plugin
and junit5
。您必须至少定义一个版本2.22.0
为了maven-surefire-plugin
(see Codefx 博客 - Junit 5 设置 https://blog.codefx.org/libraries/junit-5-setup/)或者只使用maven3.6.0
。
此外,您必须依赖于 jupiter-engine 的定义,如上面这个问题的第一行所述:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
如果您定义了对该工件的依赖关系junit-jupiter-api
仅此,足以编译测试并使用 junit5 运行,@Disabled
注释将被默默地忽略,并且特定的测试也将运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)