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.
Kluent is hosted in jCenter
dependencies {
testCompile 'org.amshove.kluent:kluent:1.3'
}
<dependency>
<groupId>org.amshove.kluent</groupId>
<artifactId>kluent</artifactId>
<version>1.3</version>
<type>pom</type>
</dependency>
All examples contain the infixNotation as well as the `backtick Notation`.
All examples can also be seen in Kluent's tests.
JUnit:
assertEquals("hello", "hello");
Kluent:
"hello" shouldEqual "hello"
OR
"hello" `should equal` "hello"
JUnit:
assertNotEquals("hello", "world");
Kluent:
"hello" shouldNotEqual "world"
OR
"hello" `should not equal` "world"
JUnit:
assertSame(firstObject, secondObject);
Kluent:
firstObject shouldBe secondObject
OR
firstObject `should be` secondObject;
JUnit:
assertNotSame(firstObject, secondObject);
Kluent:
firstObject shouldNotBe secondObject
OR
firstObject `should not be` secondObject
JUnit:
assertArrayEquals(firstArray, secondArray);
Kluent:
firstArray shouldEqual secondArray
OR
firstArray `should equal` secondArray
Kluent:
firstIterable shouldEqual secondIterable
OR
firstIterable `should equal` secondIterable
val alice = Person("Alice", "Bob")
val jon = Person("Jon", "Doe")
val list = listOf(alice, jon)
list shouldContain jon
OR
list `should contain` jon
val alice = Person("Alice", "Bob")
val jon = Person("Jon", "Doe")
val list = listOf(alice, jon)
list shouldNotContain alice
OR
list `should not contain` alice
val func = { throw IndexOutOfBoundsException() }
func shouldThrow IndexOutOfBoundsException::class
OR
func `should throw` IndexOutOfBoundsException::class
val func = { throw Exception("Hello World!") }
func shouldThrowTheException Exception::class withMessage "Hello World!"
OR
func `should throw the Exception` Exception::class `with message` "Hello World!"
val func = { throw Exception("Hello World!") }
func shouldThrow AnyException
OR
func `should throw` AnyException
val func = { throw Exception("Hello World!") }
func shouldNotThrow IndexOutOfBoundsException::class
OR
func `should not throw` IndexOutOfBoundsException::class
val func = { throw Exception("Hello World!") }
func shouldNotThrowTheException IndexOutOfBoundsException::class withMessage "Nothing here"
OR
func `should not throw the Exception` IndexOutOfBoundsException::class `with message` "Nothing here"
val func = { Unit }
func shouldNotThrow AnyException
OR
func `should not throw` AnyException