Why did I stop using JUnit?
What’s my issue?
For most of my private & work projects, I mostly use Kotlin. I can’t imagine code without tests. Until last year I have been using JUnit 5 for testing my applications. It works okay. Frequent usage gives it a ton of examples all over the Internet.
Still, you can feel that it’s a little bit clumsy. Especially when you create parameterized tests, you need to use a whole bunch of annotations & write arguments generators. Using it with Kotlin feels like a step back to over-verbose Java code.
The solution
Thanks to my colleagues, I discovered that testing Kotlin apps can be better. They introduced me to Kotest. No need to use annotations. Multiple flexible styles of writing tests in pure Kotlin. Out-of-the-box support for property-based testing. Just take a look at this example:
Why should you try it?
Besides that Kotest is clean & flexible, it has a vast list of useful perks, like:
- a plugin for IntelliJ
- support for Kotlin’s coroutines
- a previously-mentioned property-based tests module
- an assertions module
- multiple extensions, among others for:
- Spring
- Testcontainers
- Pitest
- and many more
- runs on JUnit Platform, so if you already have tests based on JUnit then you can migrate them test by test without fuss.
Give it a try next time you’re starting a new Kotlin project. If you want to know more about Kotest, check out this list of articles.