Best practices for unit testing in Kotlin

Click for: original source

Philipp Hauer post about how unit testing in Kotlin is fun and tricky at the same time. We can benefit a lot from Kotlin’s powerful language features to write readable and concise unit tests. His post contains the best practices and guidelines to write unit test code in Kotlin that is idiomatic, readable, concise and produces reasonable failure messages.

Some interesting points raised in the article:

  • What is idiomatic Kotlin code?
  • Avoid static and reuse the test class instance
  • Change the lifecycle default for every test class
  • Use backticks and @nested inner classes
  • How to handle the mocks

… and much more. There are many Kotlin libraries setting out to ease testing with Kotlin, for example author suggests KotlinTest and Spek. You will also find code examples and further resources in the article. Learn more!

[Read More]

Tags programming app-development android