我正在尝试使用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>
结果如我所料。但是警告令我困惑。警告是什么意思?
2条答案
按热度按时间iq0todco1#
目前使用
junit-jupiter-engine
的5.3.x
版本与Surefire2.22.2
配合使用。看起来你被https://issues.apache.org/jira/browse/SUREFIRE-1564震惊了,它描述了一个已知的问题,即Surefire
2.22.0
内部保留在版本1.2.0
上,用于所有junit-platfrom-xyz
工件。您还应该为Surefire 3.x提供一个try - afaik,它与所有版本的JUnit都兼容:https://maven.apache.org/surefire/maven-surefire-plugin/
uyto3xhc2#
1.当您添加JUNIT 5依赖项时,它会自动包含“junit-platform-engine”和“junit-jupiter-API”。您可以在“Pom.xml”的依赖项层次结构中检查这一点。这样您就可以删除随JUNIT 5沿着添加的其他依赖项。仅JUNIT 5依赖项就足够了。
1.同时确保没有引用JUNIT 4依赖项。如果您尝试混合使用JUNIT和JUNT 5,则可能会出现此类警告,因为您正在欺骗JVM。