Annotation Type Given
@ExperimentalApi
@Documented
@Target({ANNOTATION_TYPE,FIELD,PARAMETER})
@Retention(RUNTIME)
public @interface Given
Indicates that a field or parameter should be automatically
generated with a random value during test execution.
This annotation can be applied to:
- fields
@Testmethod parameters@RepeatedTestmethod parameters- additional
@ParameterizedTestmethod parameters
@ExtendWith(InstancioExtension.class)
class ExampleTest {
@Given
private List<Person> persons;
@Test
void example1(@Given int randomInt) {
// Regular @Test method with generated parameters
}
@RepeatedTest(10)
void example2(@Given String randomString) {
// @RepeatedTest method with generated parameters
}
@ValueSource(strings = {"foo", "bar", "baz"})
@ParameterizedTest
void example3(String value, @Given LocalDate randomDate) {
// Supplement @ParameterizedTest arguments with additional generated arguments
// Augment @ParameterizedTest arguments with additional generated values
}
}
- Since:
- 5.0.0
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<? extends GivenProvider>[]Specifies classes that will provide values for the annotated parameter or field.
-
Element Details
-
value
Specifies classes that will provide values for the annotated parameter or field.- If no class is specified, Instancio will generate
random values for elements annotated with
@Given. - If multiple classes are specified, a provider will be selected randomly from the specified classes.
- Returns:
- the classes responsible for providing values
- Since:
- 5.0.0
- Default:
{}
- If no class is specified, Instancio will generate
random values for elements annotated with
-