-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
In the course of integrating @ParameterizedClass
into my codebase, I've come across a situation where I have a test that logically belongs in a test class annotated with @ParameterizedClass
, but it needs to only run once. It would be very useful to have an annotation to allow specifically marked tests to run a single time. These tests would be run before or after (default after) the @ParameterizedClass
parameterized invocations, with a parameter that can be set in the @ParameterizedClass
annotation.
Example annotation code:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
public @interface SingleInvocation {
}
Example enum code:
public enum SingleInvoker {
BEFORE, AFTER
}
Example test class code:
@ParameterizedClass(singleInvoker = SingleInvoker.BEFORE)
@ValueSource(ints = {1, 2})
public class ExecuteTestOnceInParameterizedClass {
@Parameter
private int num;
@Test
public void test1() {
}
@Test
public void test2() {
}
@SingleInvocation
@Test
public void testToRunOnce() {
}
@SingleInvocation
@ParameterizedTest
@ValueSource(strings = {"a", "b"})
public void parameterizedTestToRunOnce(String let) {
}
}
Deliverables
- ...