【问题标题】:How to have hierarchical test report with Kotlintest and Gradle如何使用 Kotlintest 和 Gradle 获得分层测试报告
【发布时间】:2019-09-23 07:38:45
【问题描述】:

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

  • Gradle 5.6.2
  • Kotlintest 3.4.2
  • JUnit 平台 1.5.2

示例测试类

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 级别?

【问题讨论】:

    标签: gradle kotlintest


    【解决方案1】:

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

    我猜你是通过 gradle 任务运行测试的?如果是这样,Idea 可以以不同的方式显示结果 这就是我通过 IDEA 中的 gradle 插件运行 gradle 测试任务时的样子

    【讨论】:

    • 没错! Gradle 方式无需插件即可工作,而 InteliJ 方式需要插件 kotlintest。如果您可以编辑您的答案并让每个人都知道“神奇”开关在哪里,那将是完美的!同时 html 报告中没有层次结构,对吗?
    猜你喜欢
    • 1970-01-01
    • 2018-09-13
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    相关资源
    最近更新 更多