在成功运行JUnit 4测试后,我正在尝试将JUnit 5与Gradle一起使用.
预期的结果: JUnit 4测试在输出中给出了一个很好的'传递',并且输入了一个html报告build/reports/tests.
实际结果: JUnit 5测试如下所示不输出任何内容(...) build succesful,虽然我知道测试实际上没有运行,因为没有传递/跳过/失败的测试日志输出,并且fail在测试中放置一个使构建成功.
在很多我认为主要是不相关的输出之间运行gradle test --info收益率Skipping task ':testClasses' as it has no actions..令人惊讶的是,它也说Executing task ':test'和Generating HTML test report... Finished generating test html resultsxml中的类似build/test-results/test,而xml没有生成,html显示没有测试运行且没有错误,测试确实没有运行.
我认为非常有趣的是gradle test --debug收益率
[TestEventLogger] Gradle Test Run :test STARTED
[org.gradle.api.internal.tasks.testing.junit.JUnitDetector] test-class-
scan : failed to scan parent class java/lang/Object, could not find the class file
[TestEventLogger]
[TestEventLogger] Gradle Test Run :test …Run Code Online (Sandbox Code Playgroud) 我已经用Kotlin和Junit 5编写了一些基本的单元测试。不幸的是,当我从Intellij IDEA运行它们时,Gradle找不到这些测试。我从Gradle收到消息“找不到给定的测试包括:[de.mhaug.phd.btcwallet.BasicTests]”,从Intellij收到消息“未收到测试事件”。
有趣的是,从命令行使用“ ./gradlew:clean:test”运行该命令可以报告构建成功。但是,我的第一个测试显然是红色的,因此这表明Gradle没有执行它。
我已经尝试使用更详细的输出来运行它,但是没有任何帮助。这是一个最小的(不是)工作示例:
package de.mhaug.phd.btcwallet
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Test
class BasicTests {
@Test
fun hey() {
assertEquals(3,1+1)
}
@Test
fun hey2() {
assertFalse(3==1+1)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的build.gradle:
buildscript {
ext.kotlin_version = '1.2.10'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'de.mhaug.phd'
version '1.0-SNAPSHOT'
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.46'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.2'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', …Run Code Online (Sandbox Code Playgroud) 从Intellij启动时,kotlintest测试运行良好,但是当我尝试使用gradle test task命令运行它们时,仅发现并运行了我的常规JUnit测试。
kotlintest代码:
import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.StringSpec
class HelloKotlinTest : StringSpec() {
init {
println("Start Kotlin UnitTest")
"length should return size of string" {
"hello".length shouldBe 5
}
}
}
Run Code Online (Sandbox Code Playgroud)
build.gradle:
apply plugin: 'org.junit.platform.gradle.plugin'
buildscript {
ext.kotlinVersion = '1.1.3'
ext.junitPlatformVersion = '1.0.0-M4'
repositories {
maven { url 'http://nexus.acompany.ch/content/groups/public' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.junit.platform:junit-platform-gradle-plugin:$junitPlatformVersion"
}
}
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
test.kotlin.srcDirs += 'test/main/kotlin'
}
(...)
dependencies {
// Kotlin
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8', version: kotlinVersion …Run Code Online (Sandbox Code Playgroud)