小编Rya*_*eod的帖子

为什么@DisplayName 在 JUnit 5 中对我不起作用?

出于某种原因,我真的很难在使用 Kotlin 的 JUnit 5 中真正尊重显示名称。这是我为示例目的创建的测试文件:

import org.assertj.core.api.Assertions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

@DisplayName("Example Test")
class ExampleTest {
    @Test
    @DisplayName("test name")
    fun myTest() {
        Assertions.assertThat(false).isTrue()
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,它没有使用这些名称,而是显示了实际的类/方法名称,就好像它们根本没有注释一样@DisplayName。这是来自的输出./gradlew test

project.path.ExampleTest > myTest() FAILED
    org.opentest4j.AssertionFailedError at ExampleTest.kt:12

25 tests completed, 1 failed

> Task :test FAILED
Run Code Online (Sandbox Code Playgroud)

我一直认为我的 Gradle 配置肯定有问题,但设置非常简单,所以我不知道我做错了什么。这是我的 build.gradle.kts:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.3.60"
    id("org.jmailen.kotlinter") version "2.1.2"
    id("org.jetbrains.kotlin.plugin.serialization") version "1.3.60"
}

version = "0.1"

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0")
    testImplementation("org.junit.jupiter:junit-jupiter:5.5.2")
    testImplementation("org.assertj:assertj-core:3.14.0") …
Run Code Online (Sandbox Code Playgroud)

junit gradle kotlin junit5

14
推荐指数
2
解决办法
5969
查看次数

标签 统计

gradle ×1

junit ×1

junit5 ×1

kotlin ×1