Pet*_*zov 6 java eclipse junit5
我想在Maven项目中使用Junit 5:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我当前要禁用测试:
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 {
....
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用。在mvn clean build之后执行测试。你能告诉我我所缺少的吗?
小智 7
这是由maven-surefire-plugin
和 之间的不兼容造成的junit5
。您要么必须至少2.22.0
为maven-surefire-plugin
(请参阅codefx blog-junit 5 setup)定义一个版本,要么只使用 maven 3.6.0
。此外,您必须依赖于上面这个问题的第一行中已经定义的 jupiter-engine :
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
如果您只定义了对工件的依赖junit-jupiter-api
,这足以让测试编译并使用 junit5 运行,则@Disabled
注释将被静默忽略,特定测试也将运行。
检查 Surefire 插件的配置是否有 junit-jupiter-engine 依赖项。我不确定,但我相信应该对其进行配置,以便加载引擎工件中的所有功能,包括禁用注释。
<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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1137 次 |
最近记录: |