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

com.tngtech.java.junit.dataprovider.UseDataProvider Maven / Gradle / Ivy

Go to download

A TestNG like dataprovider runner for JUnit having a simplified syntax compared to all the existing JUnit4 features.

The newest version!
/*
 * Copyright 2019 TNG Technology Consulting GmbH
 *
 * 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
 *
 *     http://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 com.tngtech.java.junit.dataprovider;

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;

import com.tngtech.java.junit.dataprovider.internal.DefaultDataProviderMethodResolver;

/**
 * Annotate a test method for using it with a dataprovider. The {@link #resolver()} is used to find a proper dataprovider.
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface UseDataProvider {

    enum ResolveStrategy {
        /**
         * Tries to find valid dataprovider methods looping over the provided {@link UseDataProvider#resolver()} until the first non-empty
         * result is returned or no further resolver is available.
         */
        UNTIL_FIRST_MATCH,

        /**
         * Loops over every provided {@link UseDataProvider#resolver()} and aggregates all resulting dataprovider methods. The test methods
         * to be executed are generated upon all these dataprovider methods.
         */
        AGGREGATE_ALL_MATCHES,
    }

    /**
     * This is the default value for {@link #value()}. If used the dataprovider name is tried to be guessed (= convention over
     * configuration) in the in {@link #value()} described order.
     */
    String DEFAULT_VALUE = "";

    /**
     * A value to derive the dataprovider method from. In which way depends on the given {@link #resolver()}. Defaults to
     * {@link #DEFAULT_VALUE}.
     *
     * @return a value from which the dataprovider method can be derived
     */
    String value() default DEFAULT_VALUE;

    /**
     * One or multiple locations where the {@link DataProviderMethodResolver} can look out for a proper dataprovider method. It depends on
     * the provided {@link #resolver()} how this is used.
     *
     * @return a array of {@link Class}es which could be used to derive the dataprovider method
     */
    Class[] location() default {};

    /**
     * The resolvers used to derive the dataprovider method from. It is tried until the first resolver returns a proper dataprovider method
     * (= not {@code null}) or no more resolvers are available.
     *
     * @return the resolver which are used to derive the dataprovider method
     */
    Class[] resolver() default { DefaultDataProviderMethodResolver.class };

    /**
     * @return strategy how to resolve the dataprovider methods which corresponds to the test method where this annotation is applied.
     * @see ResolveStrategy
     */
    ResolveStrategy resolveStrategy() default ResolveStrategy.UNTIL_FIRST_MATCH;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy