Konform Matchers

Kotest provides various matchers for use with Konform. They can be used in your tests to assert that a given object is validated or fails validation.

To use these matchers add implementation 'io.kotest:kotest-assertions-konform-jvm:<version>' or implementation 'io.kotest:kotest-assertions-konform-js:<version> to your build.

Let's start with a basic data class:

data class UserProfile(
val fullName: String,
val age: Int?

Then given a UserProfile validator like this:

val validateUser = Validation<UserProfile> {
UserProfile::fullName {
UserProfile::age ifPresent {

We can test that instances pass validation like this:

val alice = UserProfile("Alice", 25)
validateUser shouldBeValid user1

And we can test that instances fail validation with specific error messages like this:

val bob = UserProfile("bob", 18)
validateUser.shouldBeInvalid(a) {
it.shouldContainError(UserProfile::fullName, "must have at least 4 characters")
it.shouldContainError(UserProfile::age, "must be at least '21'")
validation.shouldBeValid(value)Asserts that the validation is valid for the given value
validation.shouldBeInvalid(value)Asserts that the validation is invalid for the given value
validation.shouldBeInvalid(value) { block }Asserts that the validation is invalid for the given value, and then, runs the block with invalid value