Kotest Support
Konsist + Kotest
Konsist has first-class support for Kotest meaning that every following release will be developed with Kotest compatibility in mind. API has been improved to support Kotest flows.
Setting The Test Name
Kotest tests are lambdas, so the test name is not present in the call stack and Konsist can't obtain it on its own. Without the test name:
The error message does not contain the test name (e.g.
Assert was violated (1 time)orTest has failed.for architecture assertions).The test can't be suppressed (See Suppress Konsist Test).
How the test name is provided depends on the Kotest version:
6.x
Register KoKotestExtension once (recommended) or pass the testName argument to every assertion
this.testCase.name.name
5.x
Pass the testName argument to every assertion (KoKotestExtension is not supported)
this.testCase.name.testName
Kotest 6: KoKotestExtension
KoKotestExtension passes the name of the running Kotest test to every Konsist assertion (assertTrue, assertFalse, assertArchitecture, etc.). The testName argument is no longer needed:
class UseCaseTest : FreeSpec({
"useCase test" {
Konsist
.scopeFromProject()
.classes()
.assertTrue { it.residesInPackage("..domain.usecase..") } // no testName
}
})The failure message contains the test name (Assert 'useCase test' was violated (1 time)) and the test can be suppressed with @Suppress("konsist.useCase test") or @Suppress("useCase test").
The extension has to be registered once. Pick one of the options:
Kotest 6 detects the project config class named ProjectConfig placed in the io.kotest.provided package (e.g. src/test/kotlin/io/kotest/provided/ProjectConfig.kt):
To use a different location set the kotest.framework.config.fqn system property (e.g. -Dkotest.framework.config.fqn=com.myapp.MyProjectConfig).
Things to know:
The test name is the name of the test itself (
this.testCase.name.name), without the names of the enclosing containers (e.g.context,describe,"group" - { }). Tests with the same name inside different containers are suppressed by the same@Suppressvalue.The test name is available inside the test coroutine, also after switching threads (e.g.
withContext(Dispatchers.IO)). It is not available in threads started manually inside the test.The
testNameargument still works and takes precedence over the name provided by the extension.
Kotest 5: testName Argument
KoKotestExtension is not supported in Kotest 5.x (Kotest 6 changed the extension API). Provide the test name using the testName argument. Kotest enables fetching the test name from the context to populate the testName argument, ensuring consistent naming of tests:
KoTestName Extension
To facilitate test name retrieval you can add a custom koTestName extension:
This extension enables more concise syntax for providing Kotest test name:
Last updated