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

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

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" shouldEqual "hello"
"hello".shouldEqual("hello")
"hello" `should equal` "hello"

assertNotEquals

"hello" shouldNotEqual "world"
"hello".shouldNotEqual("world")
"hello" `should not equal` "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)

Changelog

1.41

1.40

1.39

1.38

1.37

1.36

1.35

1.34

1.33

1.32

1.31

1.30

1.29

1.28

1.27

1.26

1.25

1.24

1.23

1.22

1.21

1.20

1.19

1.18

1.17

1.16

1.15

1.14

1.13

1.12

1.11

1.10

1.9