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.
Platform | Status |
---|---|
MacOS / Linux | |
Windows |
Guide
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)