Core assertion building blocks for Kotest testing framework providing foundational utilities like shouldBe for all platforms
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The Kotest Assertions Shared module provides the foundational assertion building blocks for the Kotest testing framework. This Kotlin multiplatform library includes core utilities like shouldBe, data-driven testing capabilities, collection inspection tools, and comprehensive error handling that are shared across the entire Kotest ecosystem.
implementation("io.kotest:kotest-assertions-shared:5.9.1")import io.kotest.matchers.shouldBe
import io.kotest.matchers.should
import io.kotest.matchers.shouldNot
import io.kotest.data.*
import io.kotest.inspectors.*
import io.kotest.assertions.*import io.kotest.matchers.shouldBe
import io.kotest.data.*
import io.kotest.inspectors.forAll
// Basic assertions
val result = "hello world"
result shouldBe "hello world"
result.length shouldBe 11
// Data-driven testing
val table = table(
headers("input", "expected"),
row("hello", 5),
row("world", 5),
row("kotlin", 6)
)
table.forAll { input, expected ->
input.length shouldBe expected
}
// Collection inspection
listOf(2, 4, 6, 8).forAll { it % 2 shouldBe 0 }Kotest Assertions Shared is built around several key components:
shouldBe/should/shouldNot DSL with extensible Matcher<T> interfaceforAll, forOne, forExactly, etc.)Basic assertion DSL providing natural language testing with shouldBe, should, and shouldNot functions. Forms the foundation of all Kotest assertions.
infix fun <T, U : T> T.shouldBe(expected: U?): T
infix fun <T> T.shouldNotBe(any: Any?): T
infix fun <T> T.should(matcher: Matcher<T>): T
infix fun <T> T.shouldNot(matcher: Matcher<T>): T
interface Matcher<T> {
fun test(value: T): MatcherResult
}Comprehensive table-based testing framework with type-safe row and table definitions supporting up to 22 columns. Perfect for parameterized tests and comprehensive test coverage.
fun <A> table(headers: Headers1, vararg rows: Row1<A>): Table1<A>
fun <A, B> table(headers: Headers2, vararg rows: Row2<A, B>): Table2<A, B>
suspend fun <A> Table1<A>.forAll(fn: suspend (A) -> Unit)
suspend fun <A, B> Table2<A, B>.forAll(fn: suspend (A, B) -> Unit)
data class Row1<out A>(val a: A)
data class Row2<out A, out B>(val a: A, val b: B)Powerful collection testing DSL with quantifier functions for asserting properties across collection elements. Supports collections, arrays, sequences, and maps.
inline fun <T, C : Collection<T>> C.forAll(fn: (T) -> Unit): C
inline fun <T, C : Collection<T>> C.forOne(fn: (T) -> Unit): C
inline fun <T, C : Collection<T>> C.forExactly(k: Int, fn: (T) -> Unit): C
inline fun <T, C : Collection<T>> C.forSome(fn: (T) -> Unit): C
inline fun <T, C : Collection<T>> C.forNone(fn: (T) -> Unit): CAdvanced error collection and reporting system with contextual clues for enhanced debugging. Supports both soft and hard error collection modes.
inline fun <R> withClue(clue: Any?, thunk: () -> R): R
inline fun <T : Any?, R> T.asClue(block: (T) -> R): R
fun failure(message: String): AssertionError
fun failure(expected: Expected, actual: Actual): Throwable
inline fun shouldFail(block: () -> Any?): AssertionErrorinterface MatcherResult {
val passed: Boolean
val failureMessage: String
val negatedFailureMessage: String
}
data class Printed(val value: String)
enum class ErrorCollectionMode { Soft, Hard }
interface Row {
fun values(): List<Any?>
}