Annotation Interface TypeGeneratorSource
@Target(METHOD)
@Retention(RUNTIME)
@Documented
@ArgumentsSource(TypeGeneratorArgumentsProvider.class)
public @interface TypeGeneratorSource
@TypeGeneratorSource is an ArgumentsSource that provides
access to values from a TypedGenerator implementation for
parameterized tests.
This annotation allows you to use any TypedGenerator implementation
directly in your parameterized tests. The generator will be instantiated using
its default constructor, and the specified number of values will be generated
and passed to your test method.
Example Usage
@ParameterizedTest
@TypeGeneratorSource(NonBlankStringGenerator.class)
void testWithGeneratedStrings(String value) {
assertNotNull(value);
assertFalse(value.isBlank());
}
@ParameterizedTest
@TypeGeneratorSource(value = IntegerGenerator.class, count = 5)
void testWithMultipleIntegers(Integer value) {
assertNotNull(value);
}
If you need to use a custom generator with specific configuration, consider
using @TypeGeneratorMethodSource instead.
- Since:
- 2.0
- Author:
- Oliver Wolff
- See Also:
-
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionClass<? extends TypedGenerator<?>> The TypedGenerator class to use for generating test values. -
Optional Element Summary
Optional Elements
-
Element Details
-
value
Class<? extends TypedGenerator<?>> valueThe TypedGenerator class to use for generating test values. Must have a no-args constructor.- Returns:
- the TypedGenerator class
-
count
int countNumber of instances to generate.- Returns:
- the number of instances to generate, defaults to 1
- Default:
1
-
seed
long seedOptional seed for reproducible tests.If set to a value other than -1, this seed will be used for the generator instead of the seed managed by
GeneratorControllerExtension.This is useful for tests that need specific generated values regardless of the global seed configuration.
- Returns:
- the seed to use, or -1 to use the globally configured seed
- Default:
-1L
-