CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Kotlin test annotations for use in common code, providing @Test, @Ignore, @BeforeTest, and @AfterTest annotations for multiplatform testing.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Kotlin Test Annotations Common

Kotlin test annotations for use in common code. Provides common test annotations like @Test, @Ignore, @BeforeTest, and @AfterTest that can be used across different platforms in Kotlin multiplatform projects.

Package Information

  • Package Name: kotlin-test-annotations-common
  • Package Type: maven
  • Language: Kotlin
  • Installation:
    • Gradle: implementation("org.jetbrains.kotlin:kotlin-test-annotations-common:2.2.0")
    • Maven: <dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-test-annotations-common</artifactId><version>2.2.0</version></dependency>

Core Imports

import kotlin.test.*

Or import specific annotations:

import kotlin.test.Test
import kotlin.test.Ignore
import kotlin.test.BeforeTest
import kotlin.test.AfterTest

Basic Usage

import kotlin.test.*

class MyTest {

    @BeforeTest
    fun setup() {
        // Setup code that runs before each test
    }

    @Test
    fun testSomething() {
        // Test implementation
    }

    @Test
    fun testAnotherThing() {
        // Another test implementation  
    }

    @Ignore
    @Test
    fun testSkipped() {
        // This test will be ignored/skipped
    }

    @AfterTest
    fun teardown() {
        // Cleanup code that runs after each test
    }
}

Capabilities

Test Marking

Mark functions as test methods that should be executed by the test framework.

@Target(AnnotationTarget.FUNCTION)
public expect annotation class Test()

The @Test annotation marks a function as a test that should be executed by the testing framework. This annotation is mapped to platform-specific test annotations:

  • JVM: Maps to JUnit's @Test, JUnit 5's @Test, or TestNG's @Test
  • JavaScript: Maps to Jasmine, Mocha, or Jest test functions
  • Native: Maps to platform-specific testing framework test markers

Test Ignoring

Skip test execution for specific tests or entire test suites.

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

The @Ignore annotation can be applied to:

  • Individual test functions to skip that specific test
  • Test classes to skip all tests in the class

When applied, the test framework will skip execution but typically report the test as ignored/skipped.

Test Setup

Execute setup code before each test method.

@Target(AnnotationTarget.FUNCTION)
public expect annotation class BeforeTest()

Functions annotated with @BeforeTest are executed before each test method in the same class. This is useful for:

  • Initializing test data
  • Setting up mock objects
  • Preparing test environment

Test Cleanup

Execute cleanup code after each test method.

@Target(AnnotationTarget.FUNCTION)
public expect annotation class AfterTest()

Functions annotated with @AfterTest are executed after each test method in the same class. This is useful for:

  • Cleaning up resources
  • Resetting state
  • Tearing down test environment

Platform Mapping

These annotations are expect declarations that map to platform-specific testing frameworks:

JVM Platforms

  • JUnit 4: Maps to @org.junit.Test, @org.junit.Ignore, @org.junit.Before, @org.junit.After
  • JUnit 5: Maps to @org.junit.jupiter.api.Test, @org.junit.jupiter.api.Disabled, @org.junit.jupiter.api.BeforeEach, @org.junit.jupiter.api.AfterEach
  • TestNG: Maps to @org.testng.annotations.Test, @org.testng.annotations.Test(enabled=false), @org.testng.annotations.BeforeMethod, @org.testng.annotations.AfterMethod

JavaScript Platforms

  • Jasmine/Mocha/Jest: Maps to it(), xit() or it.skip(), beforeEach(), afterEach()

Native Platforms

Maps to the testing framework available on the specific native platform.

Usage Notes

  1. Multiplatform Compatibility: These annotations work across all Kotlin platforms (JVM, JS, Native)
  2. Framework Agnostic: The same test code works with different testing frameworks
  3. Common Module: These annotations should be used in your commonMain or commonTest source sets
  4. Platform-Specific Implementation: Each platform provides its own implementation that maps to the appropriate testing framework
  5. Execution Order: @BeforeTest methods run before each @Test method, and @AfterTest methods run after each @Test method
  6. Class vs Function: @Ignore can be applied to both classes and functions, while other annotations only apply to functions

docs

index.md

tile.json