or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

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

JUnit 5 integration adapter for Kotlin test framework providing JUnit 5-specific assertions and test annotations

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

To install, run

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

index.mddocs/

Kotlin Test JUnit 5

Kotlin Test JUnit 5 provides seamless integration between the Kotlin multiplatform test framework and JUnit 5, enabling developers to use kotlin.test assertions and annotations with JUnit 5's testing infrastructure. It serves as a bridge that maps kotlin.test annotations to their JUnit 5 equivalents and implements kotlin.test assertions using JUnit 5's assertion engine.

Package Information

  • Package Name: kotlin-test-junit5
  • Package Type: maven (Gradle/Maven)
  • Language: Kotlin (JVM)
  • Group ID: org.jetbrains.kotlin
  • Artifact ID: kotlin-test-junit5
  • Installation:
    • Gradle: testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:2.2.0")
    • Maven: Add dependency with groupId org.jetbrains.kotlin, artifactId kotlin-test-junit5, version 2.2.0

Core Imports

import kotlin.test.*

The integration happens automatically through service provider mechanism. When JUnit 5 is detected in the classpath, kotlin.test assertions will delegate to JUnit 5's assertion engine.

Basic Usage

import kotlin.test.*

class MyTest {
    @Test
    fun testExample() {
        val result = 2 + 2
        assertEquals(4, result)
        assertTrue(result > 0)
        assertNotNull(result)
    }
    
    @BeforeTest
    fun setup() {
        // Setup before each test
    }
    
    @AfterTest
    fun cleanup() {
        // Cleanup after each test
    }
    
    @Test
    @Ignore
    fun skippedTest() {
        // This test will be skipped
    }
}

Architecture

Kotlin Test JUnit 5 works through several key components:

  • Annotation Mapping: Type aliases that map kotlin.test annotations to JUnit 5 annotations
  • Asserter Implementation: JUnit5Asserter object that delegates kotlin.test assertions to JUnit 5 assertions
  • Service Provider: JUnit5Contributor that automatically registers the asserter when JUnit 5 is available
  • Classpath Detection: Runtime detection of JUnit 5 availability without hard dependencies

Capabilities

Test Annotations

Maps kotlin.test annotations to their JUnit 5 equivalents for seamless integration.

/**
 * Marks a function as a test - maps to org.junit.jupiter.api.Test
 */
public actual typealias Test = org.junit.jupiter.api.Test

/**
 * Marks a test or suite as ignored - maps to org.junit.jupiter.api.Disabled  
 */
public actual typealias Ignore = org.junit.jupiter.api.Disabled

/**
 * Marks a function to be invoked before each test - maps to org.junit.jupiter.api.BeforeEach
 */
public actual typealias BeforeTest = org.junit.jupiter.api.BeforeEach

/**
 * Marks a function to be invoked after each test - maps to org.junit.jupiter.api.AfterEach
 */
public actual typealias AfterTest = org.junit.jupiter.api.AfterEach

Assertion Engine Integration

Provides JUnit 5 assertion engine integration through the JUnit5Asserter object.

/**
 * JUnit 5 assertion engine implementation for kotlin.test
 * Delegates all kotlin.test assertions to org.junit.jupiter.api.Assertions
 * Note: assertTrue methods are available through inherited default implementation
 */
public object JUnit5Asserter : Asserter {
    /**
     * Asserts that the specified values are equal
     * @param message the message to report if the assertion fails
     * @param expected the expected value
     * @param actual the actual value
     */
    override fun assertEquals(message: String?, expected: Any?, actual: Any?)
    
    /**
     * Asserts that the specified values are not equal
     * @param message the message to report if the assertion fails
     * @param illegal the value that should not equal actual
     * @param actual the actual value
     */
    override fun assertNotEquals(message: String?, illegal: Any?, actual: Any?)
    
    /**
     * Asserts that the specified values are the same instance
     * @param message the message to report if the assertion fails
     * @param expected the expected reference
     * @param actual the actual reference
     */
    override fun assertSame(message: String?, expected: Any?, actual: Any?)
    
    /**
     * Asserts that the specified values are not the same instance
     * @param message the message to report if the assertion fails
     * @param illegal the reference that should not be the same as actual
     * @param actual the actual reference
     */
    override fun assertNotSame(message: String?, illegal: Any?, actual: Any?)
    
    /**
     * Asserts that the specified value is not null
     * @param message the message to report if the assertion fails
     * @param actual the value to check
     */
    override fun assertNotNull(message: String?, actual: Any?)
    
    /**
     * Asserts that the specified value is null
     * @param message the message to report if the assertion fails
     * @param actual the value to check
     */
    override fun assertNull(message: String?, actual: Any?)
    
    /**
     * Fails the current test with the specified message
     * @param message the message to report
     */
    override fun fail(message: String?): Nothing
    
    /**
     * Fails the current test with the specified message and cause
     * Available since Kotlin 1.4
     * @param message the message to report
     * @param cause the exception to set as the root cause
     */
    override fun fail(message: String?, cause: Throwable?): Nothing
}

Service Provider Integration

Automatic registration system that enables JUnit 5 integration when available.

/**
 * Provides JUnit5Asserter if org.junit.jupiter.api.Assertions class is found in the classpath
 * Registered as a service provider for kotlin.test.AsserterContributor
 */
public class JUnit5Contributor : AsserterContributor {
    /**
     * Provides asserter instance or null if JUnit 5 is not available
     * @return JUnit5Asserter if JUnit 5 is in classpath, null otherwise
     */
    override fun contribute(): Asserter?
}

Types

Base Interfaces

These interfaces are defined in the kotlin.test framework and implemented by this library:

/**
 * Abstracts the logic for performing assertions
 * Specific implementations can use different testing frameworks
 */
public interface Asserter {
    /**
     * Fails the current test with the specified message
     */
    fun fail(message: String?): Nothing
    
    /**
     * Fails the current test with the specified message and cause exception
     * Available since Kotlin 1.4
     */
    fun fail(message: String?, cause: Throwable?): Nothing
    
    /**
     * Asserts that the specified value is true
     * @param lazyMessage function to return a message to report if the assertion fails
     */
    fun assertTrue(lazyMessage: () -> String?, actual: Boolean): Unit
    
    /**
     * Asserts that the specified value is true
     * @param message the message to report if the assertion fails
     */
    fun assertTrue(message: String?, actual: Boolean): Unit
    
    /**
     * Asserts that the specified values are equal
     */
    fun assertEquals(message: String?, expected: Any?, actual: Any?)
    
    /**
     * Asserts that the specified values are not equal
     */
    fun assertNotEquals(message: String?, illegal: Any?, actual: Any?)
    
    /**
     * Asserts that the specified values are the same instance
     */
    fun assertSame(message: String?, expected: Any?, actual: Any?)
    
    /**
     * Asserts that the specified values are not the same instance
     */
    fun assertNotSame(message: String?, illegal: Any?, actual: Any?)
    
    /**
     * Asserts that the specified value is null
     */
    fun assertNull(message: String?, actual: Any?)
    
    /**
     * Asserts that the specified value is not null
     */
    fun assertNotNull(message: String?, actual: Any?)
}

/**
 * Checks applicability and provides Asserter instance
 */
public interface AsserterContributor {
    /**
     * Provides Asserter instance or null depends on the current context
     * @return asserter instance or null if it is not applicable now
     */
    fun contribute(): Asserter?
}

Dependencies

  • Compile-only: org.junit.jupiter:junit-jupiter-api:5.0.0+
  • Runtime: org.junit.jupiter:junit-jupiter-engine (for test execution)
  • Runtime: org.junit.platform:junit-platform-launcher (for test discovery)
  • Transitive: kotlin-test (parent kotlin test framework)

Integration Notes

  • Automatic Detection: The library automatically detects JUnit 5 presence via classpath reflection
  • No Hard Dependencies: Uses compile-only dependency on JUnit 5 API to avoid version conflicts
  • Service Provider: Registers via Java SPI (META-INF/services/kotlin.test.AsserterContributor)
  • Module System: Provides Java 9+ module support with proper exports and service declarations
  • Thread Safety: The asserter implementation is thread-safe and works in parallel test execution