Class GeneratorControllerExtension

java.lang.Object
de.cuioss.test.generator.junit.GeneratorControllerExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.TestExecutionExceptionHandler

public class GeneratorControllerExtension extends Object implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.TestExecutionExceptionHandler
JUnit 5 extension that manages test data generation by controlling generator seeds and providing detailed failure information for test reproduction.

Features

  • Initializes generator seeds before each test
  • Supports seed configuration via GeneratorSeed annotation
  • Provides detailed failure information for test reproduction
  • Handles both method and class-level seed configuration

Usage

Can be enabled in two ways:
 // Option 1: Direct extension usage
 @ExtendWith(GeneratorControllerExtension.class)
 class MyTest {
     @Test
     void shouldGenerateData() { ... }
 }

 // Option 2: Via meta-annotation (preferred)
 @EnableGeneratorController
 class MyTest {
     @Test
     void shouldGenerateData() { ... }
 }
 

Seed Configuration

Seeds can be configured in order of precedence:
  1. Method-level @GeneratorSeed
  2. Class-level @GeneratorSeed
  3. System property de.cuioss.test.generator.seed
  4. Random seed (if no configuration present)

Failure Handling

On test failure, provides a detailed message with:
  • The original test failure message
  • The seed used for test data generation
  • Instructions for test reproduction
Author:
Oliver Wolff
See Also:
  • Constructor Details

  • Method Details

    • handleTestExecutionException

      public void handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable throwable) throws Throwable
      Specified by:
      handleTestExecutionException in interface org.junit.jupiter.api.extension.TestExecutionExceptionHandler
      Throws:
      Throwable
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback