John Herrlin
04/19/2023, 1:55 PMStringSpec
tests. They look like this:
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 SpringEmil Kantis
04/19/2023, 2:14 PMJohn Herrlin
04/19/2023, 2:30 PMtime mvn '-Dos.detected.classifier=osx-x86_64' -U clean install
sam
04/19/2023, 4:49 PMJohn Herrlin
04/19/2023, 4:55 PMsam
04/19/2023, 4:57 PMJohn Herrlin
04/19/2023, 4:59 PMsurefire
in my codebasemvn clean test
works fine, but it doesnt print "test that something works"
to stdoutEmil Kantis
04/19/2023, 5:14 PMJohn Herrlin
04/19/2023, 5:19 PM[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 thatEmil Kantis
04/19/2023, 5:20 PMkotest-runner-junit5-jvm
dependency added to your classpath?John Herrlin
04/19/2023, 5:21 PM<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>
mitch
04/21/2023, 1:16 PMobject 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`:
class ProjectConfig : AbstractProjectConfig() {
override fun extensions(): List<Extension> = listOf(
TestPrinterListener,
// SpringAutowireConstructorExtension,
// JunitXmlReporter(includeContainers = false, useTestPathAsName = true),
// ...
)
}