Search in sources :

Example 21 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project pinpoint by naver.

the class PinpointPluginTestRunner method filter.

@Override
public void filter(Filter filter) throws NoTestsRemainException {
    synchronized (childrenLock) {
        List<FrameworkMethod> children = new ArrayList<FrameworkMethod>(getFilteredChildren());
        for (Iterator<FrameworkMethod> iter = children.iterator(); iter.hasNext(); ) {
            FrameworkMethod each = iter.next();
            if (shouldRun(filter, each)) {
                try {
                    filter.apply(each);
                } catch (NoTestsRemainException e) {
                    iter.remove();
                }
            } else {
                iter.remove();
            }
        }
        filteredChildren = Collections.unmodifiableCollection(children);
        if (filteredChildren.isEmpty()) {
            throw new NoTestsRemainException();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 22 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project hibernate-orm by hibernate.

the class CustomParameterized method concatNames.

private String concatNames(List<FrameworkMethod> parametersMethods) {
    StringBuilder sb = new StringBuilder();
    for (FrameworkMethod method : parametersMethods) {
        Parameterized.Parameters parameters = method.getAnnotation(Parameterized.Parameters.class);
        if (sb.length() != 0) {
            sb.append(", ");
        }
        sb.append(parameters.name());
    }
    return sb.toString();
}
Also used : Parameterized(org.junit.runners.Parameterized) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 23 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project hibernate-orm by hibernate.

the class CustomRunner method doComputation.

protected List<FrameworkMethod> doComputation() {
    // Next, get all the test methods as understood by JUnit
    final List<FrameworkMethod> methods = super.computeTestMethods();
    // Now process that full list of test methods and build our custom result
    final List<FrameworkMethod> result = new ArrayList<FrameworkMethod>();
    final boolean doValidation = Boolean.getBoolean(Helper.VALIDATE_FAILURE_EXPECTED);
    int testCount = 0;
    Ignore virtualIgnore;
    for (FrameworkMethod frameworkMethod : methods) {
        // potentially ignore based on expected failure
        final FailureExpected failureExpected = Helper.locateAnnotation(FailureExpected.class, frameworkMethod, getTestClass());
        if (failureExpected != null && !doValidation) {
            virtualIgnore = new IgnoreImpl(Helper.extractIgnoreMessage(failureExpected, frameworkMethod));
        } else {
            virtualIgnore = convertSkipToIgnore(frameworkMethod);
        }
        testCount++;
        log.trace("adding test " + Helper.extractTestName(frameworkMethod) + " [#" + testCount + "]");
        result.add(new ExtendedFrameworkMethod(frameworkMethod, virtualIgnore, failureExpected));
    }
    return result;
}
Also used : Ignore(org.junit.Ignore) ArrayList(java.util.ArrayList) FailureExpected(org.hibernate.testing.FailureExpected) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 24 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod in project intellij-community by JetBrains.

the class GuiTestRunner method methodBlock.

@Override
protected Statement methodBlock(FrameworkMethod method) {
    FrameworkMethod newMethod;
    try {
        if (Arrays.stream(getTestClass().getAnnotations()).anyMatch(annotation -> annotation instanceof ParentPlugin)) {
            loadClassesWithNewPluginClassLoader();
        } else {
            loadClassesWithIdeClassLoader();
        }
        Method methodFromClassLoader = myTestClass.getJavaClass().getMethod(method.getName());
        newMethod = new FrameworkMethod(methodFromClassLoader);
    } catch (Exception e) {
        return new Fail(e);
    }
    Object test;
    try {
        test = new ReflectiveCallable() {

            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (Throwable e) {
        return new Fail(e);
    }
    Statement statement = methodInvoker(newMethod, test);
    List<FrameworkMethod> beforeMethods = myTestClass.getAnnotatedMethods(Before.class);
    if (!beforeMethods.isEmpty()) {
        statement = new RunBefores(statement, beforeMethods, test);
    }
    List<FrameworkMethod> afterMethods = myTestClass.getAnnotatedMethods(After.class);
    if (!afterMethods.isEmpty()) {
        statement = new RunAfters(statement, afterMethods, test);
    }
    return statement;
}
Also used : RunAfters(org.junit.internal.runners.statements.RunAfters) ReflectiveCallable(org.junit.internal.runners.model.ReflectiveCallable) Statement(org.junit.runners.model.Statement) Method(java.lang.reflect.Method) FrameworkMethod(org.junit.runners.model.FrameworkMethod) RunBefores(org.junit.internal.runners.statements.RunBefores) FrameworkMethod(org.junit.runners.model.FrameworkMethod) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Fail(org.junit.internal.runners.statements.Fail)

Example 25 with FrameworkMethod

use of org.junit.runners.model.FrameworkMethod 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)

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