View on GitHub

Kluent

Fluent Assertion-Library for Kotlin

Kluent

Kluent is a “Fluent Assertions” library written specifically for Kotlin.

It uses the Infix-Notations and Extension Functions of Kotlin to provide a fluent wrapper around JUnit-Asserts and Mockito.

How to contribute

Contributors

Changelog

Download

Platform Status
MacOS / Linux Build Status
Windows Build status

Guide

Basic Assertions

Numerical Assertions

CharSequence Assertions

Collection Assertions

Exception handling

Mocking

java.time Assertions

FileSystem

Define own assertions

Equivalency assertions

Softly assertions

Using backticks

Every method that is included in Kluent also has a “backtick version”, to make it feel more like a describing sentence.

Some examples:

assertEquals

"hello" shouldBeEqualTo "hello"
"hello".shouldBeEqualTo("hello")
"hello" `should be equal to` "hello"

assertNotEquals

"hello" shouldNotBeEqualTo "world"
"hello".shouldNotBeEqualTo("world")
"hello" `should not be equal to` "world"

Collections

shouldBeEmpty

shouldNotBeEmpty

CharSequence

shouldBeEmpty

shouldNotBeEmpty

shouldBeBlank

shouldNotBeBlank

CharSequence?

shouldBeNullOrEmpty

shouldNotBeNullOrEmpty

shouldBeNullOrBlank

shouldNotBeNullOrBlank

Nullables

shouldBeNull

shouldNotBeNull

Boolean

shouldBeTrue

shouldBeFalse

shouldNotBeTrue

shouldNotBeFalse

Chaining of assertions

val number = 42

number
        .shouldBePositive()
        .shouldBeGreaterThan(10)
        .shouldBeLessThan(43)
        .shouldBeInRange(40..45)
        .shouldNotBeInRange(45..50)