Package de.cuioss.test.generator.junit
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
GeneratorSeedannotation - 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:- Method-level
@GeneratorSeed - Class-level
@GeneratorSeed - System property
de.cuioss.test.generator.seed - 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) voidhandleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable throwable)
-
Constructor Details
-
GeneratorControllerExtension
public GeneratorControllerExtension()
-
-
Method Details
-
handleTestExecutionException
public void handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable throwable) throws Throwable - Specified by:
handleTestExecutionExceptionin interfaceorg.junit.jupiter.api.extension.TestExecutionExceptionHandler- Throws:
Throwable
-
beforeEach
- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-