我在试着用JUnit5。
首先,我向maven项目添加了依赖项:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>然后,我创建了一个测试:
package com.example.multicurrency;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class JunitTests {
@Test
void testAssertTrue() {
assertTrue(false);
}
}在那之后,我运行测试。以下是我得到的信息:
org.junit.platform.launcher.core.DefaultLauncher handleThrowable
warning: TestEngine with ID 'junit-vintage' failed to discover tests
java.lang.NoClassDefFoundError: org/junit/platform/engine/support/filter/ExclusionReasonConsumingFilter
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter
org.opentest4j.AssertionFailedError:
Expected :<true>
Actual :<false>结果正如我所料。但是这个警告把我搞糊涂了。警告是什么意思?
发布于 2018-09-21 16:29:46
现在将junit-jupiter-engine的5.3.x版本与Surefire 2.22.2一起使用。
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>似乎你被https://issues.apache.org/jira/browse/SUREFIRE-1564震撼了,它描述了一个已知的问题,即对于所有的junit-platfrom-xyz工件,2.22.0内部都停留在1.2.0版本上。
你也应该给Surefire 3.x一个试用版,它兼容所有版本的JUnit:https://maven.apache.org/surefire/maven-surefire-plugin/
https://stackoverflow.com/questions/52439379
复制相似问题