kotest / kotest-intellij-plugin

The official Kotest plugin for Intellij and Android Studio
Apache License 2.0
181 stars 25 forks source link

Kotest plugin should not remove suffix () of dataTestName's result #288

Open xuanswe opened 8 months ago

xuanswe commented 8 months ago
class KoTest : ShouldSpec({
  class Data(val expected: IntArray) : WithDataTestName {
    override fun dataTestName() =
      "result should be (${expected.joinToString()})"
  }
  context("KoTestContext(a)") {
    withData(sequence {
      yield(Data(intArrayOf()))
      yield(Data(intArrayOf(1)))
    }) {
      fail("")
    }
  }
})
class JunitTest {
  @Test
  fun `result should be ()`() {
  }

  @Test
  fun `result should be (1)`() {
  }
}
plugins {
  kotlin("jvm") version "1.9.22"
}

repositories {
  mavenCentral()
  gradlePluginPortal()
}

dependencies {
  testImplementation(kotlin("test"))

  val kotestVersion = "5.8.0"
  testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
  testImplementation("io.kotest:kotest-property:$kotestVersion")
  `testImplementation("io.kotest:kotest-framework-datatest:$kotestVersion")`
}

tasks {
  wrapper {
    gradleVersion = "8.6"
    distributionType = Wrapper.DistributionType.ALL
  }

  test {
    useJUnitPlatform()
  }
}

tasks.withType<Test>().configureEach {
  useJUnitPlatform()
}

Actual

UI shows incorrect test name KoTestContext > result should be

Gradle log prints correct test name KoTestContext(a) > result should be () FAILED

image

Expected

UI should always show correct test names in the whole hierarchy exactly as in gradle log.

In this example, it should be KoTestContext(a) > result should be ()

xuanswe commented 8 months ago

If now I have

object KotestProjectConfig : AbstractProjectConfig() {
  override var displayFullTestPath: Boolean? = true
}

image

sksamuel commented 8 months ago

It works for me image

In your build settings for gradle, what do you have set for test runner ?

xuanswe commented 8 months ago

Hi @sksamuel,

Below is how I run the tests via IntelliJ IDEA's GUI.

IntelliJ IDEA 2023.3.4 (Ultimate Edition)
Build #IU-233.14475.28, built on February 13, 2024
Non-Bundled Plugins:
  kotest-plugin-intellij (1.3.74-IC-2023.3)
Kotlin: 233.14475.28-IJ

image

Right click on "test" directory and select "Modify Run Configuration" image

image

image

image

It seems the "Kotest Run Configuration" is not created, but a "Gradle Run Configuration" is created in my case. I think "Gradle Run Configuration" is good thing because my project has both tests written with Kotest (new tests) and JUnit (legacy tests). But then, which one is the problem in this case? Kotest reports wrong info to Gradle, or Gradle reports wrong info to IDE, or IDE shows wrong info even everything is correct?

Note that, even though, it's a "Gradle Run Configuration", Kotest plugin is still needed, so that IDE can detect tests to create menu buttons.