Multiplatform testing framework providing unified API for writing tests across all Kotlin platforms with assertions and test annotations.
—
Platform-agnostic test annotations that automatically map to the appropriate testing framework on each platform (JUnit, JUnit 5, TestNG, Jasmine, Mocha, etc.).
Marks a function as a test method.
@Target(AnnotationTarget.FUNCTION)
annotation class TestUsage:
import kotlin.test.Test
class MyTests {
@Test
fun shouldReturnCorrectValue() {
// Test implementation
}
}Platform Mappings:
@org.junit.Test@org.junit.jupiter.api.Test@org.testng.annotations.TestMarks a function to be invoked before each test method.
@Target(AnnotationTarget.FUNCTION)
annotation class BeforeTestUsage:
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:
@org.junit.Before@org.junit.jupiter.api.BeforeEach@org.testng.annotations.BeforeMethodMarks a function to be invoked after each test method.
@Target(AnnotationTarget.FUNCTION)
annotation class AfterTestUsage:
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:
@org.junit.After@org.junit.jupiter.api.AfterEach@org.testng.annotations.AfterMethodMarks a test class or test method to be ignored/skipped during test execution.
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class IgnoreUsage:
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:
@org.junit.Ignore@org.junit.jupiter.api.Disabled@org.testng.annotations.Test(enabled = false)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:
Install with Tessl CLI
npx tessl i tessl/maven-org-jetbrains-kotlin--kotlin-test