如何使用 Kotlintest 和 Gradle 生成分层测试报告

How to have hierarchical test report with Kotlintest and Gradle

我正在尝试使用 Gradle 从 Kotlintest 获取分层测试报告。我看过一些允许它的屏幕截图,但是,我没有运气。对于任何类型的测试(FunSpec、WordSpec、BehaviorSpec 等),我总是只看到 class 名称,然后是 "leaf" 测试。

样本测试class

import io.kotlintest.matchers.string.shouldStartWith
import io.kotlintest.specs.FunSpec

class HierarchicalTest : FunSpec({
    context("Here is a context 1") {
        test("Test 1") {
            "abc".shouldStartWith("a")
        }
    }

    context("Here is a context 2") {
        test("Test 2") {
            "abc".shouldStartWith("b")
        }
    }
})

build.gradle

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.41'
}

sourceCompatibility = 1.8

repositories {
    jcenter()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testImplementation 'ch.qos.logback:logback-classic:1.2.3'
    testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.4.2'
    testImplementation 'org.junit.platform:junit-platform-engine:1.5.2'
}

test {
    useJUnitPlatform()
}

IntelliJ 结果

Gradle 报告

我需要做什么才能在报告中显示 context 级别?

我正在使用 Idea 2018.3.2,我使用您的资源重新创建了项目,对我来说它有效。我想这种行为与您 运行 测试的方式有关。因为我 运行 通过 Idea 进行测试,它是测试的绿色箭头。

我猜你 运行 通过 gradle 任务进行测试?如果是这样,Idea 可以显示不同的结果 这就是我在 IDEA

中通过 gradle 插件 运行 gradle 测试任务时的样子