Hey, We are using `StringSpec` tests. They look li...
# kotest
j
Hey, We are using
StringSpec
tests. They look like this:
Copy code
init {
        "test that something works" {
            val rules = setupMocks()
            ...
        }
     ...
When I run the test suite I cant see the
test that something works
text. How can I enable this? Using Spring
e
can you clarify how you're running the test suite, and show a screen shot of where you expect to see the text?
j
This is how I run the test suite:
time mvn '-Dos.detected.classifier=osx-x86_64' -U clean install
I would expect "test that something works" to be included in the output to stdout
but it's not, and it makes it really hard to pinpoint what test that failed
s
does install run tests ?
what about mvn clean test ?
j
Yes it does. Let me see
s
Did you setup the surefire plugin to run tests
j
Good question, im not the one who set it up, let me find out
I could not find anything related to
surefire
in my codebase
mvn clean test
works fine, but it doesnt print
"test that something works"
to stdout
e
So what's configured to run tests? Surefire is one such plugin, which integrates with JUnit platform (Which Kotest also integrates with.)
j
Copy code
[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) @ service ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
So it seems that Im using
surefire
, sorry for that
e
Do you have
kotest-runner-junit5-jvm
dependency added to your classpath?
j
Yeah I looks like so.
Copy code
<dependency>
            <groupId>io.kotest</groupId>
            <artifactId>kotest-runner-junit5-jvm</artifactId>
            <version>${kotest-runner.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>objenesis</artifactId>
                    <groupId>org.objenesis</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>kotlinx-coroutines-test-jvm</artifactId>
                    <groupId>org.jetbrains.kotlinx</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>kotlinx-coroutines-core-jvm</artifactId>
                    <groupId>org.jetbrains.kotlinx</groupId>
                </exclusion>
            </exclusions>
        </dependency>
m
@John Herrlin hmm did the test run but it just didn’t output anything? can you add this
Copy code
object TestPrinterListener : TestListener {
  /**
   * Resolves the test name together with all the contexts, separated by "-"
   *
   * context - when something - when another - should do xyz
   */
  private tailrec fun resolveTestName(
    current: TestCase,
    separator: String = " - ",
    acc: String = ""
  ): String {
    val name = if (acc.isEmpty()) current.name.testName else "${current.name.testName}$separator$acc"
    return when (val parent = current.parent) {
      null -> name
      else -> resolveTestName(parent, separator, name)
    }
  }

  override suspend fun finalizeSpec(kclass: KClass<out Spec>, results: Map<TestCase, TestResult>) {
    val testCases = results.filter { it.key.type == TestType.Test }
    println(
      listOf(
        "~~~ ${kclass.simpleName} ~~~",
        *testCases
          .map { (testCase, result) -> "  + ${resolveTestName(testCase)}: TestResult=$result" }
          .toTypedArray()
      ).joinToString("\n", "\n")
    )
  }
}
and then register it in your `ProjectConfig`:
Copy code
class ProjectConfig : AbstractProjectConfig() {
  override fun extensions(): List<Extension> = listOf(
    TestPrinterListener,
    // SpringAutowireConstructorExtension, 
    // JunitXmlReporter(includeContainers = false, useTestPathAsName = true),
    // ...
  )
}
see if it prints out anything?