diff --git a/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java b/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java index 6a8c5be9dd..9d08f68330 100644 --- a/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java +++ b/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java @@ -412,6 +412,10 @@ public class JenkinsRule implements TestRule, RootAction { } public Statement apply(final Statement base, final Description description) { + if (description.getAnnotation(WithoutJenkins.class) != null) { + // request has been made to not create the instance for this test method + return tempFolder.apply(base, description); + } return tempFolder.apply(new Statement() { @Override public void evaluate() throws Throwable { diff --git a/test/src/main/java/org/jvnet/hudson/test/WithoutJenkins.java b/test/src/main/java/org/jvnet/hudson/test/WithoutJenkins.java new file mode 100644 index 0000000000..90c6a35240 --- /dev/null +++ b/test/src/main/java/org/jvnet/hudson/test/WithoutJenkins.java @@ -0,0 +1,19 @@ +package org.jvnet.hudson.test; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * An annotation for test methods that do not require the {@link JenkinsRule} to create and tear down the jenkins + * instance. + */ +@Retention(RUNTIME) +@Documented +@Target(METHOD) +public @interface WithoutJenkins { +}