CtrlK
BlogDocsLog inGet started
Tessl Logo

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.

Pending
Overview
Eval results
Files

annotations.mddocs/

Test Annotations

Platform-agnostic test annotations that automatically map to the appropriate testing framework on each platform (JUnit, JUnit 5, TestNG, Jasmine, Mocha, etc.).

Capabilities

Test Annotation

Marks a function as a test method.

@Target(AnnotationTarget.FUNCTION)
annotation class Test

Usage:

import kotlin.test.Test

class MyTests {
    @Test
    fun shouldReturnCorrectValue() {
        // Test implementation
    }
}

Platform Mappings:

  • JVM (JUnit): @org.junit.Test
  • JVM (JUnit 5): @org.junit.jupiter.api.Test
  • JVM (TestNG): @org.testng.annotations.Test
  • JavaScript: Framework-specific test registration
  • Native/WASM: Framework-specific test registration

BeforeTest Annotation

Marks a function to be invoked before each test method.

@Target(AnnotationTarget.FUNCTION)
annotation class BeforeTest

Usage:

import kotlin.test.BeforeTest
import kotlin.test.Test

class MyTests {
    private lateinit var testData: String
    
    @BeforeTest
    fun setup() {
        testData = "initialized"
    }
    
    @Test
    fun testWithSetup() {
        assertEquals("initialized", testData)
    }
}

Platform Mappings:

  • JVM (JUnit): @org.junit.Before
  • JVM (JUnit 5): @org.junit.jupiter.api.BeforeEach
  • JVM (TestNG): @org.testng.annotations.BeforeMethod
  • JavaScript: Framework-specific setup hooks
  • Native/WASM: Framework-specific setup hooks

AfterTest Annotation

Marks a function to be invoked after each test method.

@Target(AnnotationTarget.FUNCTION)
annotation class AfterTest

Usage:

import kotlin.test.AfterTest
import kotlin.test.Test

class MyTests {
    private var resource: AutoCloseable? = null
    
    @Test
    fun testWithResource() {
        resource = openResource()
        // Test using resource
    }
    
    @AfterTest
    fun cleanup() {
        resource?.close()
        resource = null
    }
}

Platform Mappings:

  • JVM (JUnit): @org.junit.After
  • JVM (JUnit 5): @org.junit.jupiter.api.AfterEach
  • JVM (TestNG): @org.testng.annotations.AfterMethod
  • JavaScript: Framework-specific teardown hooks
  • Native/WASM: Framework-specific teardown hooks

Ignore Annotation

Marks a test class or test method to be ignored/skipped during test execution.

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

Usage:

import kotlin.test.Ignore
import kotlin.test.Test

class MyTests {
    @Test
    fun runningTest() {
        // This test will run
    }
    
    @Test
    @Ignore
    fun skippedTest() {
        // This test will be skipped
    }
}

@Ignore
class SkippedTestClass {
    @Test
    fun thisWillBeSkipped() {
        // Entire class is ignored
    }
}

Platform Mappings:

  • JVM (JUnit): @org.junit.Ignore
  • JVM (JUnit 5): @org.junit.jupiter.api.Disabled
  • JVM (TestNG): @org.testng.annotations.Test(enabled = false)
  • JavaScript: Framework-specific skip mechanisms
  • Native/WASM: Framework-specific skip mechanisms

Multiplatform Usage

These annotations work seamlessly across all Kotlin platforms. The same test code can be compiled for different targets:

// commonTest source set
import kotlin.test.*

class MultiplatformTest {
    @BeforeTest
    fun setup() {
        println("Setting up test")
    }
    
    @Test
    fun testMultiplatform() {
        assertEquals(4, 2 + 2)
    }
    
    @AfterTest
    fun tearDown() {
        println("Cleaning up test")
    }
}

This test will work on:

  • JVM: Using JUnit, JUnit 5, or TestNG
  • JavaScript: Using Mocha, Jest, Jasmine, or other JS test frameworks
  • Native: Using the Kotlin/Native test framework
  • WASM: Using WebAssembly-specific test runners

Install with Tessl CLI

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

docs

annotations.md

asserter.md

basic-assertions.md

collection-assertions.md

exception-testing.md

index.md

type-null-assertions.md

tile.json