首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Junit5与IntelliJ和Gradle

Junit5与IntelliJ和Gradle
EN

Stack Overflow用户
提问于 2017-08-02 13:57:37
回答 8查看 86.2K关注 0票数 39

尝试使用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时,我会遇到一些错误。

代码语言:javascript
复制
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语法。

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2017-08-02 14:18:22

添加特定的依赖项可以解决这个问题。

注意:更新2017.2.0以上的INTELLIJ,因为JUNIT启动程序有一个BUG

氧气如果你使用月食。

在下面的依赖项中,可以使用Junit5参数化测试来代替DataProvider

代码语言:javascript
复制
"org.junit.jupiter:junit-jupiter-params:5.0.0"
//for JUnit5 parametrized tests.

Junit5 API.

代码语言:javascript
复制
"org.junit.jupiter:junit-jupiter-api:5.0.0"
//JUnit5 API

如果希望在不更改语法和导入的情况下运行遗留JUnit4测试,则需要。

代码语言:javascript
复制
"org.junit.vintage:junit-vintage-engine:4:12.0"
//for legacy JUnit4 tests

编辑:07/2018年将老式跑步者的版本与木星版相匹配

如果要使用新语法和导入运行JUnit5测试,则需要。

代码语言:javascript
复制
"org.junit.jupiter:junit-jupiter-engine:5.0.0"
//for JUnit5 tests

org.junit.platform.engine.EngineDiscoveryRequest.getDiscoveryFiltersByType(Ljava/lang/Class;)Ljava/util/List;:java.lang.NoSuchMethodError

发射器

代码语言:javascript
复制
"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版本一样。

代码语言:javascript
复制
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'
    }
}
票数 35
EN

Stack Overflow用户

发布于 2019-06-07 10:12:07

我必须将JUnit的版本从5.4.0改为5.3.2,它的工作原理就像一种魅力。

票数 17
EN

Stack Overflow用户

发布于 2017-09-11 07:11:49

我使用的配置如下。

只有在使用junit4测试时,才需要老式引擎依赖项。

只有在使用参数化测试时,木星参数才是必需的。

代码语言:javascript
复制
<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>
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45462987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档