我想这两个摇篮和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
的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] 删除。
我来说两句