All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.instancio.junit.Given Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2022-2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.instancio.junit;

import org.instancio.documentation.ExperimentalApi;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Indicates that a field or parameter should be automatically
 * generated with a random value during test execution.
 *
 * 

This annotation can be applied to: * *

    *
  • fields
  • *
  • {@code @Test} method parameters
  • *
  • {@code @RepeatedTest} method parameters
  • *
  • additional {@code @ParameterizedTest} method parameters
  • *
* *
{@code
 * @ExtendWith(InstancioExtension.class)
 * class ExampleTest {
 *
 *     @Given
 *     private List 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
 *     }
 * }
 * }
* * @see GivenProvider * @since 5.0.0 */ @ExperimentalApi @Documented @Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) public @interface Given { /** * 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 {@code @Given}.
  • *
  • If multiple classes are specified, a provider will be * selected randomly from the specified classes.
  • *
* * @return the classes responsible for providing values * @since 5.0.0 */ @ExperimentalApi Class[] value() default {}; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy