Fork me on GitHub

Alex Rupérez

Link: http://j.mp/2x0AyjU
Published: 13 Sep 16:46
I starred MarkusAmshove/Kluent at GitHub.
Fluent Assertion-Library for Kotlin
View on GitHub


View README


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 the JUnit-Asserts and Mockito.

Download Build Status

Changelog

Documentation


Include it via gradle/maven

Kluent is hosted here at jcenter

Kluent-Android is hosted here at jcenter

Gradle

Replace {version} with the current version

dependencies {
    testCompile 'org.amshove.kluent:kluent:{version}'

    // for Android:
    testImplementation 'org.amshove.kluent:kluent-android:{version}'
}

Maven

Replace {version} with the current version

<dependency>
    <groupId>org.amshove.kluent</groupId>
    <artifactId>kluent</artifactId>
    <version>{version}</version>
    <type>pom</type>
</dependency>

Examples

More examples can be seen on the Site or in the tests.

assertEquals

"hello" shouldEqual "hello"

assertNotEquals

"hello" shouldNotEqual "world"

Assert that an Array/Iterable contains something

val alice = Person("Alice", "Bob")
val jon = Person("Jon", "Doe")
val list = listOf(alice, jon)
list shouldContain jon

Stubbing

val stub = mock(Database::class)
val bob = Person("Bob", "Guy")
When calling stub.getPerson() itReturns bob

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" `should equal` "hello"

assertNotEquals

"hello" `should not equal` "world"