CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Kotlin Test library for experimental WebAssembly JS platform - provides test framework adapters and assertions for testing Kotlin/Wasm applications that target JavaScript environments

Pending
Overview
Eval results
Files

annotations.mddocs/

Test Annotations

Test annotations for marking functions as tests and controlling test lifecycle. These annotations provide the foundation for organizing and running Kotlin tests in WebAssembly JavaScript environments.

Capabilities

Test Annotation

Marks a function as a test case that should be executed by the test framework.

/**
 * Marks a function as a test.
 * 
 * Only functions of a class are supported as test functions.
 * Test functions must have no parameters and return type Unit.
 */
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Test

Usage Example:

import kotlin.test.*

class MyTests {
    @Test
    fun simpleTest() {
        assertEquals(4, 2 + 2)
    }
    
    @Test
    fun stringTest() {
        val message = "Hello, World!"
        assertTrue(message.isNotEmpty())
        assertContains(message, "World")
    }
    
    @Test
    fun asyncTest(): Promise<*> {
        return Promise.resolve("async result").then { result ->
            assertEquals("async result", result)
        }
    }
}

Before Test Annotation

Marks a function to be invoked before each test in a test class.

/**
 * Marks a function to be invoked before each test case.
 * 
 * Only functions of a class are supported as before test functions.
 * Before test functions must have no parameters and return type Unit.
 */
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class BeforeTest

Usage Example:

import kotlin.test.*

class DatabaseTests {
    private lateinit var database: TestDatabase
    
    @BeforeTest
    fun setup() {
        database = TestDatabase()
        database.connect()
        database.initializeTestData()
    }
    
    @Test
    fun testUserCreation() {
        val user = database.createUser("test@example.com")
        assertNotNull(user)
        assertEquals("test@example.com", user.email)
    }
    
    @Test
    fun testUserDeletion() {
        val user = database.createUser("delete@example.com")
        database.deleteUser(user.id)
        assertNull(database.findUser(user.id))
    }
}

After Test Annotation

Marks a function to be invoked after each test in a test class.

/**
 * Marks a function to be invoked after each test case.
 * 
 * Only functions of a class are supported as after test functions.
 * After test functions must have no parameters and return type Unit.
 */
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class AfterTest

Usage Example:

import kotlin.test.*

class FileSystemTests {
    private val tempFiles = mutableListOf<String>()
    
    @Test
    fun testFileCreation() {
        val fileName = "test-${System.currentTimeMillis()}.txt"
        createTestFile(fileName)
        tempFiles.add(fileName)
        
        assertTrue(fileExists(fileName))
    }
    
    @AfterTest
    fun cleanup() {
        // Clean up any files created during the test
        tempFiles.forEach { fileName ->
            deleteFile(fileName)
        }
        tempFiles.clear()
    }
}

Ignore Annotation

Marks a test function or test class as ignored, preventing it from being executed.

/**
 * Marks a test or test class as ignored.
 * Ignored tests are not executed by the test framework.
 * 
 * @param value optional reason for ignoring the test
 */
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Ignore(val value: String = "")

Usage Examples:

import kotlin.test.*

class FeatureTests {
    
    @Test
    fun workingTest() {
        assertEquals(2 + 2, 4)
    }
    
    @Ignore("Feature not implemented yet")
    @Test
    fun futureFeatureTest() {
        // This test won't run until @Ignore is removed
        fail("This feature is not ready")
    }
    
    @Ignore("Flaky test - investigating")
    @Test
    fun flakyTest() {
        // Temporarily ignored due to intermittent failures
        assertTrue(Math.random() > 0.5) // This would be flaky
    }
}

@Ignore("Entire class under development")
class ExperimentalTests {
    
    @Test
    fun experimentalFeature1() {
        // None of these tests will run because the class is ignored
        fail("Not ready")
    }
    
    @Test
    fun experimentalFeature2() {
        fail("Not ready")
    }
}

Annotation Usage Guidelines

Test Lifecycle Order:

  1. @BeforeTest functions are called before each individual test
  2. @Test function is executed
  3. @AfterTest functions are called after each individual test

Class vs Function Ignoring:

  • When a class is marked with @Ignore, all tests in that class are ignored
  • When individual functions are marked with @Ignore, only those specific tests are ignored
  • Ignored tests are typically reported as "skipped" by test frameworks

Best Practices:

  • Use @BeforeTest for test setup that needs to be fresh for each test
  • Use @AfterTest for cleanup to prevent test isolation issues
  • Always provide a reason when using @Ignore to help future maintainers
  • Avoid long-lived ignored tests - either fix them or remove them
  • Test functions should be focused and test a single concern

Install with Tessl CLI

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

docs

annotations.md

asserter-system.md

assertions.md

framework-integration.md

index.md

tile.json