尝试使用java8 + Junit5将我的项目迁移到IntelliJ 2017.2
我增加了junit-jupiter-api版本的5.0.0-M6
和junit-platform-launcher版本1.0.0-M6
项目结构是默认的maven约定src/test/java。
找到了几篇关于这方面的文章,但都没有解决我的问题。
--它在控制台中运行良好,我认为这与IntelliJ默认的JUnit运行程序有关,或者我缺少了一些依赖项?
当我运行一个测试类时,一切正常,但是当我像以前一样选择目录和Run all 'Tests' in Java时,我会遇到一些错误。
WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests
java.lang.NoSuchMethodError: org.junit.platform.engine.TestDescriptor.pruneTree()V
Aug 02, 2017 2:44:56 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-vintage' failed to discover tests
java.lang.NoSuchMethodError: org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List;
Aug 02, 2017 2:44:56 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests
java.lang.NoSuchMethodError: org.junit.platform.engine.TestDescriptor.pruneTree()V
Aug 02, 2017 2:44:56 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-vintage' failed to discover tests
java.lang.NoSuchMethodError: org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List;备注:我还没有迁移任何测试,都是Junit 4语法。
发布于 2017-08-02 14:18:22
添加特定的依赖项可以解决这个问题。
注意:更新2017.2.0以上的INTELLIJ,因为JUNIT启动程序有一个BUG
氧气如果你使用月食。
在下面的依赖项中,可以使用Junit5参数化测试来代替DataProvider。
"org.junit.jupiter:junit-jupiter-params:5.0.0"
//for JUnit5 parametrized tests.Junit5 API.
"org.junit.jupiter:junit-jupiter-api:5.0.0"
//JUnit5 API如果希望在不更改语法和导入的情况下运行遗留JUnit4测试,则需要。
"org.junit.vintage:junit-vintage-engine:4:12.0"
//for legacy JUnit4 tests编辑:07/2018年将老式跑步者的版本与木星版相匹配
如果要使用新语法和导入运行JUnit5测试,则需要。
"org.junit.jupiter:junit-jupiter-engine:5.0.0"
//for JUnit5 testsorg.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List;:java.lang.NoSuchMethodError
发射器。
"org.junit.platform:junit-platform-launcher:1.0.0
//to handle default launcher线程"main“java.lang.NoSuchMethodError: java.lang.NoSuchMethodError中的异常
如何安装JUnit5的附加信息
自从版本4.6forGradle以来,就不再需要插件了,Gradle本机支持Junit5就行了:和老式跑步者的版本现在和JUnit 5版本一样。
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
}
test {
useJUnitPlatform {
includeEngines 'junit-jupiter', 'junit-vintage'
}
}发布于 2019-06-07 10:12:07
我必须将JUnit的版本从5.4.0改为5.3.2,它的工作原理就像一种魅力。
发布于 2017-09-11 07:11:49
我使用的配置如下。
只有在使用junit4测试时,才需要老式引擎依赖项。
只有在使用参数化测试时,木星参数才是必需的。
<properties>
<junit.version>5.0.0</junit.version>
</properties>
...
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>4.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>https://stackoverflow.com/questions/45462987
复制相似问题