Search in sources :

Example 51 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project spring-framework by spring-projects.

the class SpringMethodRule method apply.

/**
	 * Apply <em>instance-level</em> and <em>method-level</em> features of
	 * the <em>Spring TestContext Framework</em> to the supplied {@code base}
	 * statement.
	 * <p>Specifically, this method invokes the
	 * {@link TestContextManager#prepareTestInstance prepareTestInstance()},
	 * {@link TestContextManager#beforeTestMethod beforeTestMethod()}, and
	 * {@link TestContextManager#afterTestMethod afterTestMethod()} methods
	 * on the {@code TestContextManager}, potentially with Spring timeouts
	 * and repetitions.
	 * <p>In addition, this method checks whether the test is enabled in
	 * the current execution environment. This prevents methods with a
	 * non-matching {@code @IfProfileValue} annotation from running altogether,
	 * even skipping the execution of {@code prepareTestInstance()} methods
	 * in {@code TestExecutionListeners}.
	 * @param base the base {@code Statement} that this rule should be applied to
	 * @param frameworkMethod the method which is about to be invoked on the test instance
	 * @param testInstance the current test instance
	 * @return a statement that wraps the supplied {@code base} with instance-level
	 * and method-level features of the Spring TestContext Framework
	 * @see #withBeforeTestMethodCallbacks
	 * @see #withAfterTestMethodCallbacks
	 * @see #withPotentialRepeat
	 * @see #withPotentialTimeout
	 * @see #withTestInstancePreparation
	 * @see #withProfileValueCheck
	 */
@Override
public Statement apply(Statement base, FrameworkMethod frameworkMethod, Object testInstance) {
    Method testMethod = frameworkMethod.getMethod();
    if (logger.isDebugEnabled()) {
        logger.debug("Applying SpringMethodRule to test method [" + testMethod + "]");
    }
    Class<?> testClass = testInstance.getClass();
    validateSpringClassRuleConfiguration(testClass);
    TestContextManager testContextManager = SpringClassRule.getTestContextManager(testClass);
    Statement statement = base;
    statement = withBeforeTestMethodCallbacks(statement, testMethod, testInstance, testContextManager);
    statement = withAfterTestMethodCallbacks(statement, testMethod, testInstance, testContextManager);
    statement = withTestInstancePreparation(statement, testInstance, testContextManager);
    statement = withPotentialRepeat(statement, testMethod, testInstance);
    statement = withPotentialTimeout(statement, testMethod, testInstance);
    statement = withProfileValueCheck(statement, testMethod, testInstance);
    return statement;
}
Also used : Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) TestContextManager(org.springframework.test.context.TestContextManager)

Example 52 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project Ebselen by Ardesco.

the class SeleniumJUnitRunner method computeTestMethods.

@Override
protected List<FrameworkMethod> computeTestMethods() {
    List<FrameworkMethod> classMethods = getTestClass().getAnnotatedMethods(SeleniumTestAnnotations.SeleniumTest.class);
    SortedMap<Integer, FrameworkMethod> sortedTestMethodList = new TreeMap<Integer, FrameworkMethod>();
    for (FrameworkMethod seleniumTest : classMethods) {
        if (seleniumTest.getAnnotation(SeleniumTestAnnotations.Order.class) != null) {
            sortedTestMethodList.put(seleniumTest.getAnnotation(SeleniumTestAnnotations.Order.class).value(), seleniumTest);
        }
    }
    return new ArrayList<FrameworkMethod>(sortedTestMethodList.values());
}
Also used : FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 53 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project robolectric by robolectric.

the class SandboxTestRunner method invokeBeforeClass.

private void invokeBeforeClass(final Class clazz) throws Throwable {
    if (!loadedTestClasses.contains(clazz)) {
        loadedTestClasses.add(clazz);
        final TestClass testClass = new TestClass(clazz);
        final List<FrameworkMethod> befores = testClass.getAnnotatedMethods(BeforeClass.class);
        for (FrameworkMethod before : befores) {
            before.invokeExplosively(null);
        }
    }
}
Also used : TestClass(org.junit.runners.model.TestClass) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 54 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project robolectric by robolectric.

the class RobolectricTestRunner method createClassLoaderConfig.

/**
   * Create an {@link InstrumentationConfiguration} suitable for the provided {@link Config}.
   *
   * Custom TestRunner subclasses may wish to override this method to provide alternate configuration.
   *
   * @param config the merged configuration for the test that's about to run -- todo
   * @return an {@link InstrumentationConfiguration}
   * @deprecated Override {@link #createClassLoaderConfig(FrameworkMethod)} instead
   */
@Deprecated
@NotNull
public InstrumentationConfiguration createClassLoaderConfig(Config config) {
    FrameworkMethod method = ((MethodPassThrough) config).method;
    Builder builder = new InstrumentationConfiguration.Builder(super.createClassLoaderConfig(method));
    AndroidConfigurer.configure(builder, getInterceptors());
    AndroidConfigurer.withConfig(builder, config);
    return builder.build();
}
Also used : Builder(org.robolectric.internal.bytecode.InstrumentationConfiguration.Builder) FrameworkMethod(org.junit.runners.model.FrameworkMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 55 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project randomizedtesting by randomizedtesting.

the class RandomizedRunner method wrapMethodRules.

/**
   * Wrap the given statement in any declared MethodRules (old style rules).
   */
@SuppressWarnings("deprecation")
private Statement wrapMethodRules(Statement s, TestCandidate c, Object instance) {
    FrameworkMethod fm = new FrameworkMethod(c.method);
    // Old-style MethodRules first.
    List<org.junit.rules.MethodRule> methodRules = getAnnotatedFieldValues(instance, Rule.class, org.junit.rules.MethodRule.class);
    for (org.junit.rules.MethodRule rule : methodRules) {
        s = rule.apply(s, fm, instance);
    }
    // New-style TestRule next.
    List<TestRule> testRules = getAnnotatedFieldValues(instance, Rule.class, TestRule.class);
    for (TestRule rule : testRules) {
        s = rule.apply(s, c.description);
    }
    return s;
}
Also used : TestRule(org.junit.rules.TestRule) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Aggregations

FrameworkMethod (org.junit.runners.model.FrameworkMethod)59 ArrayList (java.util.ArrayList)15 Statement (org.junit.runners.model.Statement)13 TestClass (org.junit.runners.model.TestClass)13 Test (org.junit.Test)11 Method (java.lang.reflect.Method)10 MethodRule (org.junit.rules.MethodRule)5 Fail (org.junit.internal.runners.statements.Fail)4 RunBefores (org.junit.internal.runners.statements.RunBefores)4 TestRule (org.junit.rules.TestRule)4 Parameterized (org.junit.runners.Parameterized)3 Interaction (au.com.dius.pact.model.Interaction)2 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)2 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)2 ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)2 Provider (au.com.dius.pact.provider.junit.Provider)2 TargetRequestFilter (au.com.dius.pact.provider.junit.TargetRequestFilter)2 BounceMemberRule (com.hazelcast.test.bounce.BounceMemberRule)2 EmptyStatement (com.hazelcast.util.EmptyStatement)2 URL (java.net.URL)2