Kotlin Unit Test Framework: KotlinTest


#1

I thought recently that Kotlin would need a powerful testing framework like ScalaTest. Now I’m happy someone actually ported it to Kotlin and named it … KotlinTest! It doesn’t support all features of ScalaTest yet, but it looks promising.

I’m a fan of flatspec, since it is pretty readable without introducing too much nested blocks and documentation nobody cares about. Confusing unit tests with “executable specs”, like other testing styles do, is not very helpful, since such tests are not read by business users. In my opinion it is much better to keep unit tests clean, simple and flat and use a BDD framework like Cucumber for high-level acceptance tests. So for me, it’s great news to hear about KotlinTest!


#2

As the author, I’m pleased you like it. Please create any tickets on github if you need extra features. Did you find it via the kotlin blog I put up yesterday?


#3

Yes, I’ve found it via Kotlin for Scala Developers. Maybe KotlinTest is worth a separate blog post …


#4

I have written a KotlinTest blog. The boss will post it next week.


#5

im just trying it out in a gradle project.
in intellij everything is fine, but when running gradle test it does not work.
eg this test passes in gradle but fails in IJ

``
class AnotherTest() : FunSpec(), Logging {
override val log: Logger by lazyLogger()

init {
    test("fails") {
        log.debug("log sth")
        false shouldBe true
    }
}

override fun afterAll() {
    super.afterAll()
}

}
``

test result output is
``

<?xml version="1.0" encoding="UTF-8"?> ``

#6

I’ve created ticket here https://github.com/kotlintest/kotlintest/issues/8
I’ll work it asap


#7

That’s fixed in 1.0.5 which I just pushed to maven central. Thanks for bug report.