CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-junit-platform--junit-platform-launcher

JUnit Platform Launcher provides APIs for discovering and executing tests on the JUnit Platform, typically used by IDEs and build tools

Pending
Overview
Eval results
Files

configuration.mddocs/

Configuration and Factory

Flexible launcher configuration and factory patterns supporting both default and custom configurations with auto-registration control and service provider integration.

Capabilities

LauncherFactory Class

Factory for creating Launcher instances with optional custom configuration. Provides both session-based and direct launcher creation.

/**
 * Factory for creating Launcher instances
 */
class LauncherFactory {
    /**
     * Open launcher session with default configuration
     * @return LauncherSession with default settings
     */
    static LauncherSession openSession();
    
    /**
     * Open launcher session with custom configuration
     * @param config - LauncherConfig specifying custom settings
     * @return LauncherSession with custom configuration
     */
    static LauncherSession openSession(LauncherConfig config);
    
    /**
     * Create launcher with default configuration
     * @return Launcher instance with default settings
     */
    static Launcher create();
    
    /**
     * Create launcher with custom configuration
     * @param config - LauncherConfig specifying custom settings
     * @return Launcher instance with custom configuration
     */
    static Launcher create(LauncherConfig config);
}

Usage Examples:

import org.junit.platform.launcher.core.*;

// Default launcher
Launcher defaultLauncher = LauncherFactory.create();

// Session-based usage
try (LauncherSession session = LauncherFactory.openSession()) {
    Launcher launcher = session.getLauncher();
    // Use launcher for multiple operations
}

// Custom configuration
LauncherConfig config = LauncherConfig.builder()
    .enableTestEngineAutoRegistration(false)
    .addTestEngines(new MyCustomTestEngine())
    .addTestExecutionListeners(new MyCustomListener())
    .build();

Launcher customLauncher = LauncherFactory.create(config);

LauncherConfig Interface

Configuration API for creating Launchers with fine-grained control over auto-registration and additional components.

/**
 * Configuration API for creating Launchers
 */
interface LauncherConfig {
    /**
     * Check if test engine auto-registration is enabled
     * @return true if auto-registration enabled, false otherwise
     */
    boolean isTestEngineAutoRegistrationEnabled();
    
    /**
     * Check if launcher session listener auto-registration is enabled
     * @return true if auto-registration enabled, false otherwise
     */
    boolean isLauncherSessionListenerAutoRegistrationEnabled();
    
    /**
     * Check if launcher discovery listener auto-registration is enabled
     * @return true if auto-registration enabled, false otherwise
     */
    boolean isLauncherDiscoveryListenerAutoRegistrationEnabled();
    
    /**
     * Check if test execution listener auto-registration is enabled
     * @return true if auto-registration enabled, false otherwise
     */
    boolean isTestExecutionListenerAutoRegistrationEnabled();
    
    /**
     * Check if post-discovery filter auto-registration is enabled
     * @return true if auto-registration enabled, false otherwise
     */
    boolean isPostDiscoveryFilterAutoRegistrationEnabled();
    
    /**
     * Get additional test engines to register
     * @return Collection of TestEngine instances
     */
    Collection<TestEngine> getAdditionalTestEngines();
    
    /**
     * Get additional launcher session listeners to register
     * @return Collection of LauncherSessionListener instances
     */
    Collection<LauncherSessionListener> getAdditionalLauncherSessionListeners();
    
    /**
     * Get additional launcher discovery listeners to register
     * @return Collection of LauncherDiscoveryListener instances
     */
    Collection<LauncherDiscoveryListener> getAdditionalLauncherDiscoveryListeners();
    
    /**
     * Get additional test execution listeners to register
     * @return Collection of TestExecutionListener instances
     */
    Collection<TestExecutionListener> getAdditionalTestExecutionListeners();
    
    /**
     * Get additional post-discovery filters to register
     * @return Collection of PostDiscoveryFilter instances
     */
    Collection<PostDiscoveryFilter> getAdditionalPostDiscoveryFilters();
    
    /**
     * Create new configuration builder
     * @return LauncherConfig.Builder instance
     */
    static Builder builder();
}

LauncherConfig.Builder Class

Builder for creating LauncherConfig instances with fluent API.

/**
 * Builder for creating LauncherConfig instances
 */
interface Builder {
    /**
     * Enable or disable test engine auto-registration
     * @param enabled - Whether to enable auto-registration
     * @return This builder for method chaining
     */
    Builder enableTestEngineAutoRegistration(boolean enabled);
    
    /**
     * Enable or disable launcher session listener auto-registration
     * @param enabled - Whether to enable auto-registration
     * @return This builder for method chaining
     */
    Builder enableLauncherSessionListenerAutoRegistration(boolean enabled);
    
    /**
     * Enable or disable launcher discovery listener auto-registration
     * @param enabled - Whether to enable auto-registration
     * @return This builder for method chaining
     */
    Builder enableLauncherDiscoveryListenerAutoRegistration(boolean enabled);
    
    /**
     * Enable or disable test execution listener auto-registration
     * @param enabled - Whether to enable auto-registration
     * @return This builder for method chaining
     */
    Builder enableTestExecutionListenerAutoRegistration(boolean enabled);
    
    /**
     * Enable or disable post-discovery filter auto-registration
     * @param enabled - Whether to enable auto-registration
     * @return This builder for method chaining
     */
    Builder enablePostDiscoveryFilterAutoRegistration(boolean enabled);
    
    /**
     * Add additional test engines
     * @param testEngines - TestEngine instances to add
     * @return This builder for method chaining
     */
    Builder addTestEngines(TestEngine... testEngines);
    
    /**
     * Add additional launcher session listeners
     * @param listeners - LauncherSessionListener instances to add
     * @return This builder for method chaining
     */
    Builder addLauncherSessionListeners(LauncherSessionListener... listeners);
    
    /**
     * Add additional launcher discovery listeners
     * @param listeners - LauncherDiscoveryListener instances to add
     * @return This builder for method chaining
     */
    Builder addLauncherDiscoveryListeners(LauncherDiscoveryListener... listeners);
    
    /**
     * Add additional test execution listeners
     * @param listeners - TestExecutionListener instances to add
     * @return This builder for method chaining
     */
    Builder addTestExecutionListeners(TestExecutionListener... listeners);
    
    /**
     * Add additional post-discovery filters
     * @param filters - PostDiscoveryFilter instances to add
     * @return This builder for method chaining
     */
    Builder addPostDiscoveryFilters(PostDiscoveryFilter... filters);
    
    /**
     * Build the LauncherConfig
     * @return Configured LauncherConfig instance
     */
    LauncherConfig build();
}

Usage Examples:

import org.junit.platform.launcher.core.*;
import org.junit.platform.launcher.listeners.*;

// Disable auto-registration and provide custom components
LauncherConfig customConfig = LauncherConfig.builder()
    .enableTestEngineAutoRegistration(false)
    .enableTestExecutionListenerAutoRegistration(false)
    .addTestEngines(new MyCustomEngine())
    .addTestExecutionListeners(
        new SummaryGeneratingListener(),
        LoggingListener.forJavaUtilLogging()
    )
    .build();

// Selective auto-registration
LauncherConfig selectiveConfig = LauncherConfig.builder()
    .enableTestEngineAutoRegistration(true)           // Enable engine discovery
    .enableTestExecutionListenerAutoRegistration(false) // Disable listener discovery
    .addTestExecutionListeners(new MySpecificListener()) // Add specific listeners
    .build();

// Complete custom configuration
LauncherConfig fullCustomConfig = LauncherConfig.builder()
    .enableTestEngineAutoRegistration(false)
    .enableLauncherSessionListenerAutoRegistration(false)
    .enableLauncherDiscoveryListenerAutoRegistration(false)
    .enableTestExecutionListenerAutoRegistration(false)
    .enablePostDiscoveryFilterAutoRegistration(false)
    .addTestEngines(
        new JupiterTestEngine(),
        new MyCustomEngine()
    )
    .addLauncherSessionListeners(new MySessionListener())
    .addLauncherDiscoveryListeners(
        LauncherDiscoveryListeners.logging(),
        new MyDiscoveryListener()
    )
    .addTestExecutionListeners(
        new SummaryGeneratingListener(),
        new MyExecutionListener()
    )
    .addPostDiscoveryFilters(new MyCustomFilter())
    .build();

// Use with factory
Launcher launcher = LauncherFactory.create(fullCustomConfig);

LauncherConstants Class

Collection of constants related to Launcher configuration parameters.

/**
 * Collection of constants related to Launcher configuration
 */
class LauncherConstants {
    /** Property name for capturing stdout during test execution */
    String CAPTURE_STDOUT_PROPERTY_NAME = "junit.platform.output.capture.stdout";
    
    /** Property name for capturing stderr during test execution */
    String CAPTURE_STDERR_PROPERTY_NAME = "junit.platform.output.capture.stderr";
    
    /** Property name for maximum buffer size when capturing output */
    String CAPTURE_MAX_BUFFER_PROPERTY_NAME = "junit.platform.output.capture.maxBuffer";
    
    /** Default maximum buffer size for capturing output (1MB) */
    int CAPTURE_MAX_BUFFER_DEFAULT = 1024 * 1024;
    
    /** Property name for deactivating listeners matching a pattern */
    String DEACTIVATE_LISTENERS_PATTERN_PROPERTY_NAME = "junit.platform.listeners.deactivate";
    
    /** Pattern for deactivating all listeners */
    String DEACTIVATE_ALL_LISTENERS_PATTERN = "*";
    
    /** Property name for enabling launcher interceptors */
    String ENABLE_LAUNCHER_INTERCEPTORS = "junit.platform.launcher.interceptors.enabled";
    
    /** Property name for enabling dry run mode (discovery only) */
    String DRY_RUN_PROPERTY_NAME = "junit.platform.execution.dryrun";
    
    /** Property name for specifying output directory */
    String OUTPUT_DIR_PROPERTY_NAME = "junit.platform.output.dir";
    
    /** Property name for enabling stacktrace pruning */
    String STACKTRACE_PRUNING_ENABLED_PROPERTY_NAME = "junit.platform.stacktrace.pruning.enabled";
    
    /** Report entry key for captured stdout */
    String STDOUT_REPORT_ENTRY_KEY = "stdout";
    
    /** Report entry key for captured stderr */
    String STDERR_REPORT_ENTRY_KEY = "stderr";
    
    /** Placeholder for unique numbers in output directory names */
    String OUTPUT_DIR_UNIQUE_NUMBER_PLACEHOLDER = "{unique-number}";
}

Usage Examples:

import org.junit.platform.launcher.LauncherConstants;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;

// Configure request with launcher constants
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(selectPackage("com.example"))
    .configurationParameter(LauncherConstants.CAPTURE_STDOUT_PROPERTY_NAME, "true")
    .configurationParameter(LauncherConstants.CAPTURE_STDERR_PROPERTY_NAME, "true")
    .configurationParameter(LauncherConstants.OUTPUT_DIR_PROPERTY_NAME, "/tmp/test-output")
    .build();

// Dry run mode (discovery only, no execution)
LauncherDiscoveryRequest dryRunRequest = LauncherDiscoveryRequestBuilder.request()
    .selectors(selectPackage("com.example"))
    .configurationParameter(LauncherConstants.DRY_RUN_PROPERTY_NAME, "true")
    .build();

// Disable specific listeners
LauncherDiscoveryRequest filteredRequest = LauncherDiscoveryRequestBuilder.request()
    .selectors(selectPackage("com.example"))
    .configurationParameter(
        LauncherConstants.DEACTIVATE_LISTENERS_PATTERN_PROPERTY_NAME, 
        "org.example.SlowListener"
    )
    .build();

Service Provider Interface (SPI)

The launcher uses Java's ServiceLoader mechanism for auto-registration of components:

Test Engines

Create META-INF/services/org.junit.platform.engine.TestEngine:

com.example.MyCustomTestEngine
com.example.AnotherTestEngine

Test Execution Listeners

Create META-INF/services/org.junit.platform.launcher.TestExecutionListener:

com.example.MyExecutionListener
com.example.ReportingListener

Launcher Session Listeners

Create META-INF/services/org.junit.platform.launcher.LauncherSessionListener:

com.example.MySessionListener

Discovery Listeners

Create META-INF/services/org.junit.platform.launcher.LauncherDiscoveryListener:

com.example.MyDiscoveryListener

Post-Discovery Filters

Create META-INF/services/org.junit.platform.launcher.PostDiscoveryFilter:

com.example.MyCustomFilter

Configuration Precedence

Configuration sources are processed in this order (highest to lowest precedence):

  1. Programmatic Configuration - LauncherConfig builder settings
  2. System Properties - JVM system properties
  3. Configuration Parameters - LauncherDiscoveryRequest configuration
  4. Auto-discovered Components - ServiceLoader-discovered implementations
  5. Default Values - Built-in defaults

Environment Variables and System Properties

Key system properties that affect launcher behavior:

  • junit.platform.output.capture.stdout - Capture stdout output
  • junit.platform.output.capture.stderr - Capture stderr output
  • junit.platform.listeners.deactivate - Deactivate listeners by pattern
  • junit.platform.launcher.interceptors.enabled - Enable interceptors
  • junit.platform.execution.dryrun - Enable dry run mode
  • junit.platform.output.dir - Set output directory

Custom Component Integration

Example of creating and integrating custom components:

// Custom test engine
public class MyTestEngine implements TestEngine {
    @Override
    public String getId() { return "my-engine"; }
    
    @Override
    public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
        // Implementation
    }
    
    @Override
    public void execute(ExecutionRequest executionRequest) {
        // Implementation
    }
}

// Custom listener
public class MyExecutionListener implements TestExecutionListener {
    @Override
    public void executionStarted(TestIdentifier testIdentifier) {
        // Custom logic
    }
    
    @Override
    public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult result) {
        // Custom logic
    }
}

// Integration via configuration
LauncherConfig config = LauncherConfig.builder()
    .addTestEngines(new MyTestEngine())
    .addTestExecutionListeners(new MyExecutionListener())
    .build();

Launcher launcher = LauncherFactory.create(config);

Install with Tessl CLI

npx tessl i tessl/maven-org-junit-platform--junit-platform-launcher

docs

configuration.md

core-operations.md

discovery-requests.md

filters.md

index.md

listeners.md

test-plan.md

tile.json