How to upgrade to Kotest 4.0?

Paweł Weselak
Apr 11 · 3 min read

Changes in the new version of the Kotlin testing library

Man on a mountain road cycling towards the rising sun.
Man on a mountain road cycling towards the rising sun.
Photo by Pixabay on Pexels

Intro

In my previous post titled “Suppressing KotlinTest mutiny” I described how my team solved various issues we faced while implementing test cases in Kotlintest, the testing library for Kotlin. Recently there was a major release of that library. Let’s see what has been changed and what steps need to be taken to make use of the newest version of the library.

What’s your name, KotlinTest?

The most obvious change in the library is its name. The name was changed to Kotest, because of too much similarity with JetBrains kotlin.test package.

I started the migration with updating the project dependencies. The current version of the library is 4.0.3. In addition to changing the group names and the module names, I had to add one more dependency for core assertions. Moreover, Kotest is now available also for platforms other than JVM. So it is required to suffix module names with “-jvm”.

dependencyManagement {
dependencies {
dependencySet("io.kotest:4.0.3") {
entry("kotest-runner-junit5-jvm")
entry("kotest-runner-console-jvm")
entry("kotest-assertions-core-jvm")
entry("kotest-extensions-spring-jvm")
}
}
}

Please bear in mind that if you are using KotlinTest Gradle plugin, its name currently is the same as before.

Where the heck are all the assertions and specs?

Kotest creators restructured the project quite a bit. A lot of classes and functions changed their locations in packages. So the next step of the migration is to fix the imports. Spec types now reside in io.kotest.core.spec.style, and functions like should, shouldBe andshouldNot were moved to io.kotest.matchers package, while assertSoftly can be found in a package named io.kotest.assertions.

I think this can be quickly dealt with by applying find and replace in the project scope:

There could be more changes like these, but I think in most cases these are sufficient.

Project config

In Kotest 4.0, the project configuration class doesn’t have to be placed in the package io.kotlintest.provided. We can now create a configuration class wherever we want, and Kotest will automatically scan the classpath to find it. It is worth noting that ProjectLevelConfig class has been removed. I used the more general Extension interface to fill the gap.

import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.extensions.Extension
import io.kotest.spring.SpringAutowireConstructorExtension
class ProjectConfig : AbstractProjectConfig() {
override fun extensions(): List<Extension> =
listOf(SpringAutowireConstructorExtension)
}

Last but not least

Finally, I needed to update the Kotlin language version. There was a problem in the runtime. The definition of the class kotlin.time.MonotonicTimeSource could not be found. Kotest is using experimental Kotlin features for profiling and measuring the time of test execution. I updated to the latest version of Kotlin language, and it fixed the issue.

What about fixes?

I didn’t have a chance to take a closer look, but I’ve noticed that the arrow dependency issue, I described in the previous article, doesn’t occur anymore. 🎉

More information regarding new features and bug fixes you can find in the Kotest changelog.


Originally published at https://pawelweselak.com on April 11, 2020.

VirtusLab

Virtus Lab company blog

Thanks to Myroslav Golub, Mikołaj Kondratek, and Konrad Jakubiec

Paweł Weselak

Written by

Founder of “Paweł Weselak pragmatyczne programowanie”. I have over 10 years of experience in software development.

VirtusLab

VirtusLab

Virtus Lab company blog

Paweł Weselak

Written by

Founder of “Paweł Weselak pragmatyczne programowanie”. I have over 10 years of experience in software development.

VirtusLab

VirtusLab

Virtus Lab company blog

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store