Laz*_*ana 24 java junit intellij-idea
IntelliJ 2017.2我添加了junit-jupiter-api版本5.0.0-M6
和junit-platform-launcher版本1.0.0-M6
项目结构是默认的maven约定 src/test/java
找到了几篇关于此的文章,但没有一篇确实解决了我的问题.
它在控制台中运行得很好,我认为这与IntelliJ默认的JUnit Runner有关,或者我缺少一些依赖项?
当我运行单个测试类时,一切正常,但是当我选择目录并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;
Run Code Online (Sandbox Code Playgroud)
注意:我还没有迁移任何测试,都是Junit 4语法.
Laz*_*ana 27
添加特定依赖项可以解决问题.
注意:2017.2.0以上更新INTELLIJ因为JUNIT发射器有一个BUG
OXYGEN,如果你使用eclipse.
以下依赖项启用Junit5参数化测试,可以使用它们代替DataProvider.
"org.junit.jupiter:junit-jupiter-params:5.0.0"
//for JUnit5 parametrized tests.
Run Code Online (Sandbox Code Playgroud)
Junit5 API.
"org.junit.jupiter:junit-jupiter-api:5.0.0"
//JUnit5 API
Run Code Online (Sandbox Code Playgroud)
如果要在不更改语法和导入的情况下运行旧版JUnit4测试,则需要.
"org.junit.vintage:junit-vintage-engine:4:12.0"
//for legacy JUnit4 tests
Run Code Online (Sandbox Code Playgroud)
编辑次数:07/2018将老式跑步者的版本与木星版本相匹配
如果要使用新语法和导入运行JUnit5测试,则需要.
"org.junit.jupiter:junit-jupiter-engine:5.0.0"
//for JUnit5 tests
Run Code Online (Sandbox Code Playgroud)
java.lang.NoSuchMethodError:org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List;
发射器.
"org.junit.platform:junit-platform-launcher:1.0.0
//to handle default launcher
Run Code Online (Sandbox Code Playgroud)
线程"main"中的异常java.lang.NoSuchMethodError:org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
其他信息如何安装JUnit5
从Gradle版本4.6开始,不再需要插件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'
}
}
Run Code Online (Sandbox Code Playgroud)
swe*_*tfa 10
我使用的配置如下.
只有在使用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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31396 次 |
| 最近记录: |