or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

collection-inspectors.mdcore-matchers.mddata-driven-testing.mderror-handling.mdindex.md
tile.json

tessl/maven-io-kotest--kotest-assertions-shared-jvm

Core assertion building blocks for Kotest testing framework providing foundational utilities like shouldBe for all platforms

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.kotest/kotest-assertions-shared-jvm@5.9.x

To install, run

npx @tessl/cli install tessl/maven-io-kotest--kotest-assertions-shared-jvm@5.9.0

index.mddocs/

Kotest Assertions Shared

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.

Package Information

  • Package Name: io.kotest:kotest-assertions-shared-jvm
  • Package Type: maven
  • Language: Kotlin
  • Installation: implementation("io.kotest:kotest-assertions-shared:5.9.1")

Core Imports

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.*

Basic Usage

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 }

Architecture

Kotest Assertions Shared is built around several key components:

  • Matcher System: Core shouldBe/should/shouldNot DSL with extensible Matcher<T> interface
  • Data-Driven Testing: Table-based testing framework supporting up to 22-column tables with type safety
  • Collection Inspectors: Comprehensive set of quantifier functions (forAll, forOne, forExactly, etc.)
  • Error Management: Sophisticated error collection and reporting with contextual clues
  • Print System: Extensible value printing and formatting system for test output
  • Multiplatform Support: Consistent API across JVM, JavaScript, Native, and WebAssembly targets

Capabilities

Core Matchers

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
}

Core Matchers

Data-Driven Testing

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)

Data-Driven Testing

Collection Inspectors

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): C

Collection Inspectors

Error Handling & Context

Advanced 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?): AssertionError

Error Handling

Common Types

interface 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?>
}