News from KotlinTest
mediumIn the last weeks KotlinTest got some new and useful features:
Testing for Exceptions
val exception = shouldThrow<IllegalAccessException> {
// code in here that you expect to throw an IllegalAccessException
}
exception.message should start with "Something went wrong"
Before and after each
override fun beforeEach() {
println("Test starting")
}
override fun afterEach() {
println("Test completed")
}
Test configuration
Each test case can followed by a call to the config
function.
To execute a test two times with two threads you would write:
class MyTests : ShouldSpec() {
init {
should("return the length of the string") {
"sammy".length shouldBe 5
"".length shouldBe 0
}.config(invocations = 10, threads = 2)
}
}
You can tag tests to be able run them selectively:
...
}.config(tags = listOf("database", "linux"))
Timeouts are configured like this:
...
}.config(timeout = 2, timeoutUnit = TimeUnit.SECONDS)
To ignore a test, you set ignored
to true:
...
}.config(ignored = true)
Future
Some more features like property based (and table driven) testing are on the roadmap.