Search in sources :

Example 26 with TestClass

use of org.junit.runners.model.TestClass in project android by JetBrains.

the class GuiTestRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    if (GraphicsEnvironment.isHeadless()) {
        // checked first because IdeTestApplication.getInstance below (indirectly) throws an AWTException in a headless environment
        return falseAssumption("headless environment");
    }
    Method methodFromClassLoader;
    try {
        ClassLoader ideClassLoader = IdeTestApplication.getInstance().getIdeClassLoader();
        Thread.currentThread().setContextClassLoader(ideClassLoader);
        myTestClass = new TestClass(ideClassLoader.loadClass(getTestClass().getJavaClass().getName()));
        methodFromClassLoader = myTestClass.getJavaClass().getMethod(method.getName());
    } catch (Exception e) {
        return new Fail(e);
    }
    return super.methodBlock(new FrameworkMethod(methodFromClassLoader));
}
Also used : TestClass(org.junit.runners.model.TestClass) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Method(java.lang.reflect.Method) AssumptionViolatedException(org.junit.AssumptionViolatedException) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Fail(org.junit.internal.runners.statements.Fail)

Example 27 with TestClass

use of org.junit.runners.model.TestClass in project ddf by codice.

the class PaxExamRule method starting.

private void starting(Description description) {
    testsExecuted++;
    String testClassName = description.getTestClass().getSimpleName();
    if (setupFailed) {
        fail(EXAM_SETUP_FAILED_MESSAGE);
    }
    TestClass testClass = new TestClass(description.getTestClass());
    try {
        runAnnotations(PostTestConstruct.class, testClass);
    } catch (Throwable throwable) {
        setupFailed = true;
        failRule(testClassName, throwable, BEFORE_EXAM_FAILURE_MESSAGE);
    }
    if (firstRun) {
        LOGGER.info("Starting test(s) for {}", testClassName);
        firstRun = false;
        testCount = getTestCount(testClass);
        try {
            runAnnotations(BeforeExam.class, testClass);
        } catch (Throwable throwable) {
            setupFailed = true;
            LOGGER.error("Failed to setup " + testClassName, throwable);
            failRule(testClassName, throwable, BEFORE_EXAM_FAILURE_MESSAGE);
        }
    }
    LOGGER.info("Starting {} ({}/{})", description.getMethodName(), testsExecuted, testCount);
}
Also used : TestClass(org.junit.runners.model.TestClass)

Example 28 with TestClass

use of org.junit.runners.model.TestClass in project pact-jvm by DiUS.

the class HttpTarget method getProviderInfo.

protected ProviderInfo getProviderInfo() {
    Provider provider = testClass.getAnnotation(Provider.class);
    final ProviderInfo providerInfo = new ProviderInfo(provider.value());
    providerInfo.setPort(port);
    providerInfo.setHost(host);
    providerInfo.setProtocol(protocol);
    providerInfo.setPath(path);
    providerInfo.setInsecure(insecure);
    if (testClass != null) {
        final List<FrameworkMethod> methods = testClass.getAnnotatedMethods(TargetRequestFilter.class);
        if (!methods.isEmpty()) {
            providerInfo.setRequestFilter((Consumer<HttpRequest>) httpRequest -> methods.forEach(method -> {
                try {
                    method.invokeExplosively(testTarget, httpRequest);
                } catch (Throwable t) {
                    throw new AssertionError("Request filter method " + method.getName() + " failed with an exception", t);
                }
            }));
        }
    }
    return providerInfo;
}
Also used : HttpRequest(org.apache.http.HttpRequest) SystemPropertyResolver(au.com.dius.pact.provider.junit.sysprops.SystemPropertyResolver) FrameworkMethod(org.junit.runners.model.FrameworkMethod) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) ValueResolver(au.com.dius.pact.provider.junit.sysprops.ValueResolver) URL(java.net.URL) HashMap(java.util.HashMap) Interaction(au.com.dius.pact.model.Interaction) Provider(au.com.dius.pact.provider.junit.Provider) HttpRequest(org.apache.http.HttpRequest) Consumer(java.util.function.Consumer) List(java.util.List) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier) TestClass(org.junit.runners.model.TestClass) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) Map(java.util.Map) TargetRequestFilter(au.com.dius.pact.provider.junit.TargetRequestFilter) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Provider(au.com.dius.pact.provider.junit.Provider)

Example 29 with TestClass

use of org.junit.runners.model.TestClass in project junit4 by junit-team.

the class RuleMemberValidatorTest method acceptMethodStaticTestRuleThatIsAlsoClassRule.

@Test
public void acceptMethodStaticTestRuleThatIsAlsoClassRule() {
    TestClass target = new TestClass(MethodTestWithStaticClassAndTestRule.class);
    CLASS_RULE_METHOD_VALIDATOR.validate(target, errors);
    assertNumberOfErrors(0);
}
Also used : TestClass(org.junit.runners.model.TestClass) Test(org.junit.Test)

Example 30 with TestClass

use of org.junit.runners.model.TestClass in project junit4 by junit-team.

the class RuleMemberValidatorTest method methodRejectArbitraryObjectWithRuleAnnotation.

@Test
public void methodRejectArbitraryObjectWithRuleAnnotation() throws Exception {
    TestClass target = new TestClass(MethodTestWithArbitraryObjectWithRuleAnnotation.class);
    RULE_METHOD_VALIDATOR.validate(target, errors);
    assertOneErrorWithMessage("The @Rule 'getArbitraryObject' must return an implementation of MethodRule or TestRule.");
}
Also used : TestClass(org.junit.runners.model.TestClass) Test(org.junit.Test)

Aggregations

TestClass (org.junit.runners.model.TestClass)60 Test (org.junit.Test)41 FrameworkMethod (org.junit.runners.model.FrameworkMethod)12 PotentialAssignment (org.junit.experimental.theories.PotentialAssignment)6 SpecificDataPointsSupplier (org.junit.experimental.theories.internal.SpecificDataPointsSupplier)6 Annotation (java.lang.annotation.Annotation)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 PluginClassLoader (com.intellij.ide.plugins.cl.PluginClassLoader)2 HashMap (java.util.HashMap)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 Interaction (au.com.dius.pact.model.Interaction)1 Pact (au.com.dius.pact.model.Pact)1 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)1 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)1 ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)1 Provider (au.com.dius.pact.provider.junit.Provider)1