本文介绍了@Disabled在JUnit5中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Maven项目中使用Junit 5:
I want to use Junit 5 in Maven project:
<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之后执行测试.你能告诉我我所缺少的吗?
But it's not working. Tests are executed after mvn clean build. Can you advise what I'm missing?
推荐答案
检查您的surefire插件配置是否具有junit-jupiter-engine依赖性.我不确定,但是我相信应该对其进行配置,以便从引擎工件中加载所有功能,包括禁用"注释.
Check your configuration of surefire plugin for junit-jupiter-engine dependency. I am not sure, but I believe it should be configured in order to load all features from engine artifact, including Disabled annotation.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.surefire.provider.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</plugin>
这篇关于@Disabled在JUnit5中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!