Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xuanswe opened this issue Mar 8, 2024 · 3 comments
Open

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

xuanswe opened this issue Mar 8, 2024 · 3 comments
Labels

Comments

@xuanswe
Copy link

xuanswe commented Mar 8, 2024

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
Copy link
Author

xuanswe commented Mar 8, 2024

If now I have

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

image

@Kantis Kantis added the pinned label Mar 8, 2024
@sksamuel
Copy link
Member

sksamuel commented Mar 9, 2024

It works for me
image

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

@xuanswe
Copy link
Author

xuanswe commented Mar 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants