摇篮项目运行JUnit 5次测试中的IntelliJ

让 - 弗朗索瓦Beauchef:

我想这两个摇篮和jUnit5现在。一切正常,只是我不能运行特定的JUnit测试。在“运行‘SampleTest’”选项不会出现,当我用鼠标右键单击一个测试类。

我有最新版本的IntelliJ(2016年1月3日)极限的。这里是我的build.gradle文件:

repositories {
    mavenCentral()
}

apply plugin: 'java'

version = '1.0.0-SNAPSHOT'

jar {
    baseName = 'test-project'
}

dependencies {
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.0-M1'
}

项目结构是标准的一个(像Maven的)。这里是一个测试的例子:

package com.test;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SampleTest {
  @Test public void sampleTest() {
    int test = 1;
    Assertions.assertTrue(test == 1);
  }
}

我在想什么?

编辑:

看来,摇篮不会拿起我的测试无论是。当我去build/reports/tests/index.html时,表示0的测试。

最后编辑:

继@的Dunny的答案,这里是我做过什么,使一切工作。我修改我的build.gradle文件是这样的:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M1'
    }
}

repositories {
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'org.junit.platform.gradle.plugin'

version = '1.0.0-SNAPSHOT'

jar {
    baseName = 'test-project'
}

dependencies {
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.0-M1'
    testCompile group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.0.0-M1'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.0-M1'
}

test {
    testLogging {
        events 'started', 'passed'
    }
}

在的IntelliJ,我然后打开摇篮窗口,并点击了“刷新所有项目的gradle”按钮,刷新库。

然后在我的测试类,我添加@RunWith(JUnitPlatform.class)类声明的顶部。

当我做了gradle build,结果都可以在这里:build\test-results\junit-platform\TEST-junit-jupiter.xml

dunni:

的IntelliJ 2016年1月3日不具有JUnit的5次测试的支持。但是,您可以添加注释@RunWith(JUnitPlatform.class),这将在一个JUnit 4兼容模式运行测试(你仍然可以使用所有的JUnit 5个功能)。http://junit.org/junit5/docs/current/user-guide/#running-tests-junit-platform-runner以获取更多信息。

对于摇篮,你需要包括摇篮JUnit的5插件,使支持:

buildscript {
    repositories {
        mavenCentral()
        // The following is only necessary if you want to use SNAPSHOT releases.
        // maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M1'
    }
}

apply plugin: 'org.junit.platform.gradle.plugin'

http://junit.org/junit5/docs/current/user-guide/#running-tests-build

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

JUnit的的IntelliJ 5试运行罚款摇篮任务。当作为单独的试运行有时会例外:NoClassDefFoundError的... / TestExecutionListener的

如何在运行JUnit的摇篮5和JUnit 4测试套件?

使用JaCoCo中的Android项目与摇篮

“没有测试发现给定包括”运行在IntelliJ IDEA的摇篮测试时

运行JavaFX项目中的IntelliJ与摇篮

Junit5用的IntelliJ和摇篮

使用JUnit 5和Java 9没有Maven的或摇篮

如何动态JUnit中5次测试不同参数的测试?

无法从IntelliJ IDEA运行JUnit-5测试用例

JUnit 5-使用JUnit Jupiter引擎时,IntelliJ IDEA中的测试套件为空

在IntelliJ IDEA中并行运行JUnit测试

pom.xml Maven配置以在混合Java + Kotlin项目中运行JUnit 4 + JUnit 5 Jupiter测试

在IntelliJ中运行项目

JUnit 5 Surefire Maven:如何为动态Web模块项目运行测试?

在SpringBoot项目上使用DBUNIT运行Junit测试时出错

在命令行中运行JAVA + Cucumber + JUnit Maven项目

在IntelliJ中运行Scala测试

是否可以在不编译整个项目的情况下针对IntelliJ中的特定类运行JUnit测试?

运行除IntelliJ中的JUnit类别以外的所有测试

JUnit4和JUnit5测试未在IntelliJ中运行

编译groovy项目并通过Jenkins运行JUnit测试

使用IntelliJ运行JUnit测试

无法在Intellij Idea中为scala项目运行集成测试

Junit 5和IntelliJ“未找到测试”

在依赖Javaee 6 API的Maven项目中运行JUnit测试

在Android Eclipse JUnit项目中的各个类上运行原始JUnit测试

IntelliJ:让Spring + Gradle + JUnit项目在IDE中运行

在 IntelliJ Idea 中无法识别 JUnit 5 测试

如何在多模块项目中使用 JUnit5 和 SpringBoot2 通过 gradle 而不是 intelliJ 运行测试