or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

conditional-execution.mdcore-testing.mdextension-framework.mdindex.mdparallel-io.md
tile.json

tessl/maven-org-junit-jupiter--junit-jupiter-api

JUnit Jupiter API for writing tests - Core API module of JUnit 5 that provides annotations, assertions, and test lifecycle management

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.junit.jupiter/junit-jupiter-api@5.12.x

To install, run

npx @tessl/cli install tessl/maven-org-junit-jupiter--junit-jupiter-api@5.12.0

index.mddocs/

JUnit Jupiter API

JUnit Jupiter API is the core testing framework for Java applications, providing comprehensive annotations, assertions, and test lifecycle management. It offers modern testing capabilities including conditional execution, parameterized tests, parallel execution, and an extensible architecture through its Extension Model.

Package Information

  • Package Name: junit-jupiter-api
  • Package Type: maven
  • Language: Java
  • Installation: <dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.12.2</version></dependency>
  • Module: org.junit.jupiter.api

Core Imports

import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

For specific functionality:

// Core test annotations
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterAll;

// Assertions and assumptions
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;

// Conditional execution
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.DisabledOnOs;

// Extensions
import org.junit.jupiter.api.extension.ExtendWith;

Basic Usage

import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

class CalculatorTest {

    private Calculator calculator;

    @BeforeEach
    void setUp() {
        calculator = new Calculator();
    }

    @Test
    @DisplayName("Addition of two positive numbers")
    void testAddition() {
        int result = calculator.add(2, 3);
        assertEquals(5, result, "2 + 3 should equal 5");
    }

    @Test
    void testDivisionByZero() {
        assertThrows(ArithmeticException.class, () -> {
            calculator.divide(10, 0);
        }, "Division by zero should throw ArithmeticException");
    }

    @AfterEach
    void tearDown() {
        calculator = null;
    }
}

Architecture

JUnit Jupiter API is built around several key components:

  • Annotation-Driven Testing: Core annotations (@Test, @BeforeEach, etc.) for declarative test configuration
  • Assertion Engine: Static methods in Assertions class for comprehensive test validation
  • Lifecycle Management: Hooks for test setup and teardown at method and class levels
  • Extension Framework: Pluggable architecture for custom test behavior and integrations
  • Conditional Execution: Runtime environment-based test enabling/disabling
  • Parallel Execution: Thread-safe test execution with resource management
  • Module System: Java 9+ module support with exported packages

Capabilities

Core Testing Framework

Essential testing annotations, assertions, and lifecycle management for writing Java tests. Provides the foundation for all JUnit Jupiter testing scenarios.

// Core test lifecycle annotations
@Test
@BeforeEach
@AfterEach
@BeforeAll
@AfterAll

// Test organization and metadata
@DisplayName(String value)
@Disabled(String value)
@Tag(String value)
@Nested
import java.time.Duration;
import org.junit.jupiter.api.function.Executable;

// Core assertions (static methods in Assertions class)
static void assertTrue(boolean condition);
static void assertTrue(boolean condition, String message);
static void assertFalse(boolean condition);
static void assertEquals(Object expected, Object actual);
static void assertNotEquals(Object unexpected, Object actual);
static <T extends Throwable> T assertThrows(Class<T> expectedType, Executable executable);
static void assertTimeout(Duration timeout, Executable executable);
static void assertAll(Executable... executables);

Core Testing Framework

Conditional Test Execution

Runtime environment-based test control for platform-specific, JRE-specific, and custom conditional testing scenarios.

// Operating system conditions
@EnabledOnOs(OS.LINUX)
@DisabledOnOs({OS.WINDOWS, OS.MAC})

// JRE version conditions  
@EnabledOnJre(JRE.JAVA_11)
@EnabledForJreRange(min = JRE.JAVA_8, max = JRE.JAVA_17)

// System properties and environment variables
@EnabledIfSystemProperty(named = "os.arch", matches = ".*64.*")
@EnabledIfEnvironmentVariable(named = "ENV", matches = "ci")

// Custom method conditions
@EnabledIf("customCondition")
@DisabledIf("customCondition")

Conditional Execution

Extension Framework

Comprehensive extension system for custom test behavior, dependency injection, lifecycle callbacks, and test monitoring.

// Extension registration
@ExtendWith(MyExtension.class)
@RegisterExtension
static final MyExtension extension = new MyExtension();

// Core extension interfaces
interface Extension { }
interface BeforeAllCallback extends Extension {
    void beforeAll(ExtensionContext context);
}
interface ParameterResolver extends Extension {
    boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext);
    Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext);
}

// Extension context
interface ExtensionContext {
    Optional<ExtensionContext> getParent();
    String getDisplayName();
    Set<String> getTags();
    Store getStore(Namespace namespace);
}

Extension Framework

Parallel Execution and I/O Support

Thread-safe test execution with resource management, temporary directory support, and execution control annotations.

// Parallel execution control
@Execution(ExecutionMode.CONCURRENT)
@Execution(ExecutionMode.SAME_THREAD)
@Isolated

// Resource management
@ResourceLock(value = "shared.resource", mode = ResourceAccessMode.READ)
@ResourceLock(value = "exclusive.resource", mode = ResourceAccessMode.READ_WRITE)

// Temporary directory support
@TempDir
Path tempDirectory;

@TempDir(cleanup = CleanupMode.ALWAYS)
File tempDir;

Parallel Execution and I/O Support

Types

Core Interfaces

interface TestInfo {
    String getDisplayName();
    Set<String> getTags();
    Optional<Class<?>> getTestClass();
    Optional<Method> getTestMethod();
}

interface TestReporter {
    void publishEntry(Map<String, String> map);
    void publishEntry(String key, String value);
}

interface RepetitionInfo {
    int getCurrentRepetition();
    int getTotalRepetitions();
}

Functional Interfaces

@FunctionalInterface
interface Executable {
    void execute() throws Throwable;
}

@FunctionalInterface  
interface ThrowingSupplier<T> {
    T get() throws Throwable;
}

@FunctionalInterface
interface ThrowingConsumer<T> {
    void accept(T t) throws Throwable;
}

Enums

enum TestInstance.Lifecycle {
    PER_METHOD, PER_CLASS
}

enum OS {
    AIX, FREEBSD, LINUX, MAC, OPENBSD, SOLARIS, WINDOWS, OTHER;
    
    static OS current();
    boolean isCurrentOs();
}

enum ExecutionMode {
    SAME_THREAD, CONCURRENT
}

enum ResourceAccessMode {
    READ, READ_WRITE
}

enum CleanupMode {
    DEFAULT, ALWAYS, ON_SUCCESS, NEVER
}