or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

annotations.mdasserter.mdbasic-assertions.mdcollection-assertions.mdexception-testing.mdindex.mdtype-null-assertions.md
tile.json

tessl/maven-org-jetbrains-kotlin--kotlin-test

Multiplatform testing framework providing unified API for writing tests across all Kotlin platforms with assertions and test annotations.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.jetbrains.kotlin/kotlin-test@2.2.x

To install, run

npx @tessl/cli install tessl/maven-org-jetbrains-kotlin--kotlin-test@2.2.0

index.mddocs/

Kotlin Test

Kotlin Test is a comprehensive multiplatform testing framework that provides a unified API for writing tests across all Kotlin platforms (JVM, JavaScript, Native, WASM). It offers platform-agnostic test annotations and assertion functions that work consistently across different target platforms, enabling developers to write tests once and run them everywhere.

Package Information

  • Package Name: kotlin-test
  • Package Type: maven
  • Language: Kotlin
  • Installation: Add to your build.gradle.kts:
    dependencies {
        testImplementation("org.jetbrains.kotlin:kotlin-test:2.2.0")
    }

Core Imports

import kotlin.test.*

For specific imports:

import kotlin.test.Test
import kotlin.test.BeforeTest
import kotlin.test.AfterTest
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.assertFails

Basic Usage

import kotlin.test.*

class SimpleTest {
    @Test
    fun testBasicAssertions() {
        val expected = 42
        val actual = 6 * 7
        
        assertEquals(expected, actual)
        assertTrue(actual > 0)
        assertNotNull(actual)
    }
    
    @Test
    fun testExceptionHandling() {
        assertFails {
            throw IllegalArgumentException("Test exception")
        }
        
        val exception = assertFailsWith<IllegalArgumentException> {
            throw IllegalArgumentException("Specific exception")
        }
        assertEquals("Specific exception", exception.message)
    }
    
    @BeforeTest
    fun setup() {
        // Setup code before each test
    }
    
    @AfterTest
    fun teardown() {
        // Cleanup code after each test
    }
}

Architecture

Kotlin Test is built around several key components:

  • Multiplatform Core: Common API that works across all Kotlin platforms
  • Test Annotations: Platform-agnostic annotations for test lifecycle management
  • Assertion System: Rich set of assertion functions with optional custom messages
  • Asserter Interface: Pluggable assertion backend allowing integration with different test frameworks
  • Platform Adapters: Specific implementations for JUnit, JUnit 5, TestNG, and JavaScript frameworks

Capabilities

Test Annotations

Platform-agnostic annotations for marking test functions and lifecycle methods. These annotations are mapped to platform-specific equivalents automatically.

@Target(AnnotationTarget.FUNCTION)
annotation class Test

@Target(AnnotationTarget.FUNCTION)
annotation class BeforeTest

@Target(AnnotationTarget.FUNCTION)
annotation class AfterTest

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class Ignore

Test Annotations

Basic Assertions

Core assertion functions for verifying boolean conditions, equality, and identity comparisons.

fun assertTrue(actual: Boolean, message: String? = null)
fun assertFalse(actual: Boolean, message: String? = null)

fun <T> assertEquals(expected: T, actual: T, message: String? = null)
fun <T> assertNotEquals(illegal: T, actual: T, message: String? = null)

fun <T> assertSame(expected: T, actual: T, message: String? = null)
fun <T> assertNotSame(illegal: T, actual: T, message: String? = null)

Basic Assertions

Type and Null Assertions

Assertions for type checking and null safety validation.

inline fun <reified T> assertIs(value: Any?, message: String? = null): T
inline fun <reified T> assertIsNot(value: Any?, message: String? = null)

fun <T : Any> assertNotNull(actual: T?, message: String? = null): T
fun assertNull(actual: Any?, message: String? = null)

Type and Null Assertions

Collection and Content Assertions

Comprehensive assertions for working with collections, arrays, and content comparison.

fun <T> assertContains(iterable: Iterable<T>, element: T, message: String? = null)
fun <T> assertContains(array: Array<T>, element: T, message: String? = null)
fun <K, V> assertContains(map: Map<K, V>, key: K, message: String? = null)
fun assertContains(charSequence: CharSequence, char: Char, ignoreCase: Boolean = false, message: String? = null)

fun <T> assertContentEquals(expected: Iterable<T>?, actual: Iterable<T>?, message: String? = null)
fun <T> assertContentEquals(expected: Array<T>?, actual: Array<T>?, message: String? = null)

Collection and Content Assertions

Exception and Failure Testing

Assertions for testing exception handling and failure scenarios.

fun fail(message: String? = null): Nothing
fun fail(message: String? = null, cause: Throwable? = null): Nothing

inline fun assertFails(block: () -> Unit): Throwable
inline fun <reified T : Throwable> assertFailsWith(message: String? = null, block: () -> Unit): T

inline fun <T> expect(expected: T, block: () -> T)

fun todo(block: () -> Unit)

Exception and Failure Testing

Asserter Interface

The core assertion interface that can be customized for different testing frameworks and platforms.

interface Asserter {
    fun fail(message: String?): Nothing
    fun fail(message: String?, cause: Throwable?): Nothing
    fun assertTrue(message: String?, actual: Boolean): Unit
    fun assertEquals(message: String?, expected: Any?, actual: Any?): Unit
    fun assertNotEquals(message: String?, illegal: Any?, actual: Any?): Unit
    fun assertSame(message: String?, expected: Any?, actual: Any?): Unit
    fun assertNotSame(message: String?, illegal: Any?, actual: Any?): Unit
    fun assertNull(message: String?, actual: Any?): Unit
    fun assertNotNull(message: String?, actual: Any?): Unit
}

val asserter: Asserter

Asserter Interface

Types

interface AsserterContributor {
    fun contribute(): Asserter?
}

object DefaultAsserter : Asserter