[KotlinTest] (GitHub - kotest/kotest: Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing) 1.3 was just released and brings some handy new features like property based testing and table-driven testing.
class TableExample : StringSpec(), TableTesting {
init {
"numbers should be prime" {
val table = table(
headers("a", "b"),
row(5, 5),
row(4, 6),
row(3, 7)
)
forAll(table) { a, b ->
a + b == 10
}
}
}
}
A piece of beauty is the new string spec style:
"strings.size should return size of string" {
"hello".length shouldBe 5
"hello" should haveLength(5)
}
autoClose
closes all resources after all tests:
class StringSpecExample : StringSpec() {
val reader = autoClose(StringReader("xyz"))
...
}
KotlinTest provides a bunch of new matchers:
someString should haveLength(10)
myCollection should haveSize(4)
val col = listOf(1,2,3,4,5)
col should containInAnyOrder(4,2,3)
val map = mapOf(Pair(1, "a"), Pair(2, "b"))
map should haveValue("a")
… and some more.