ktobe (pronounced as "k-TU-bi") - Kotlin multiplatform post-modern minimalistic YAGNI-driven assertion library. Heavily influenced by AssertJ.
Current development stage is alpha. First more or less stable version expected to be 0.1
dependencies {
testImplementation("dev.ktobe:ktobe:0.0.1")
}
<dependency>
<groupId>dev.ktobe</groupId>
<artifactId>ktobe</artifactId>
<version>0.0.1</version>
<scope>test</scope>
</dependency>
To check referential equality:
const val BATMAN = "Dark Knight"
val bruce = BATMAN
bruce toBe BATMAN //pass
bruce notToBe BATMAN //fail
To check structural equality:
data class Agent(val name: String, val power: Int)
val agent1 = Agent("smith", 8)
val agent2 = agent1.copy()
agent1 toBeEqual agent2 //pass
agent1 notToBeEqual agent2 //fail
Asserts can be chained, everything applied to the first object:
data class Droid(val type: String, val height: Int)
val r2d1 = Droid("Astro", 42)
val r2d2 = r2d1.copy()
r2d2 toBeEqual r2d1 notToBe r2d1 //pass
To check if collection contains an element:
val avengers = listOf("Thor", "IronMan", "Hulk", "Hawkeye")
avengers toContain "Hulk" // pass
avengers notToContain "Batman" // pass
To check that collection contains exactly the given elements in the same order:
val team = mapsOf("Rick", "Morty")
team toContainExactly listOf("Rick", "Morty") // pass
team toContainExactly listOf("Morty", "Rick") // fail
To check that set (i.e. order is not applicable) contains exactly the given elements:
val deathlyHallows = linkedSetOf("wand", "stone", "cloak")
deathlyHallows toContainOnly setOf("cloak", "wand", "stone") // pass
To check that iterable contains just the given element:
val highlanders = listOf("Connor MacLeod")
highlanders toContainJust "Connor MacLeod" // pass
To check that collection is empty:
import dev.ktobe.CollectionKeyword.empty
val usersOfThisLibrary = emptyList<String>()
usersOfThisLibrary toBe empty // pass, sigh...