Search in sources :

Example 96 with Result

use of org.junit.runner.Result in project randomizedtesting by randomizedtesting.

the class RandomizedRunner method runSuite.

/**
   * Test execution logic for the entire suite, executing under designated
   * {@link RunnerThreadGroup}.
   */
private void runSuite(final RandomizedContext context, final RunNotifier notifier) {
    final Result result = new Result();
    final RunListener accounting = result.createListener();
    notifier.addListener(accounting);
    final Randomness classRandomness = runnerRandomness.clone(Thread.currentThread());
    context.push(classRandomness);
    try {
        // Check for automatically hookable listeners.
        subscribeListeners(notifier);
        // Fire a synthetic "suite started" event.
        for (RunListener r : autoListeners) {
            try {
                r.testRunStarted(suiteDescription);
            } catch (Throwable e) {
                logger.log(Level.SEVERE, "Panic: RunListener hook shouldn't throw exceptions.", e);
            }
        }
        // Filter out test candidates to see if there's anything left.
        // If not, don't bother running class hooks.
        final List<TestCandidate> tests = getFilteredTestCandidates(notifier);
        if (!tests.isEmpty()) {
            Map<TestCandidate, Boolean> ignored = determineIgnoredTests(tests);
            if (ignored.size() == tests.size()) {
                // All tests ignored, ignore class hooks but report all the ignored tests.
                for (TestCandidate c : tests) {
                    if (ignored.get(c)) {
                        reportAsIgnored(notifier, groupEvaluator, c);
                    }
                }
            } else {
                ThreadLeakControl threadLeakControl = new ThreadLeakControl(notifier, this);
                Statement s = runTestsStatement(threadLeakControl.notifier(), tests, ignored, threadLeakControl);
                s = withClassBefores(s);
                s = withClassAfters(s);
                s = withClassRules(s);
                s = withCloseContextResources(s, LifecycleScope.SUITE);
                s = threadLeakControl.forSuite(s, suiteDescription);
                try {
                    s.evaluate();
                } catch (Throwable t) {
                    t = augmentStackTrace(t, runnerRandomness);
                    if (t instanceof AssumptionViolatedException) {
                        // Fire assumption failure before method ignores. (GH-103).
                        notifier.fireTestAssumptionFailed(new Failure(suiteDescription, t));
                        // see Rants#RANT_3
                        for (final TestCandidate c : tests) {
                            notifier.fireTestIgnored(c.description);
                        }
                    } else {
                        fireTestFailure(notifier, suiteDescription, t);
                    }
                }
            }
        }
    } catch (Throwable t) {
        notifier.fireTestFailure(new Failure(suiteDescription, t));
    }
    // Fire a synthetic "suite ended" event and unsubscribe listeners.
    for (RunListener r : autoListeners) {
        try {
            r.testRunFinished(result);
        } catch (Throwable e) {
            logger.log(Level.SEVERE, "Panic: RunListener hook shouldn't throw exceptions.", e);
        }
    }
    // Final cleanup.
    notifier.removeListener(accounting);
    unsubscribeListeners(notifier);
    context.popAndDestroy();
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) RunListener(org.junit.runner.notification.RunListener)

Example 97 with Result

use of org.junit.runner.Result in project randomizedtesting by randomizedtesting.

the class TestCustomMethodProvider method testJUnit4Valid.

@Test
public void testJUnit4Valid() throws InitializationError {
    Class<?>[] valid = { T1.class, RT1.class };
    for (Class<?> cl : valid) {
        Result r = new JUnitCore().run(new RandomizedRunner(cl));
        Assert.assertEquals(0, r.getFailureCount());
        Assert.assertEquals(1, r.getRunCount());
    }
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 98 with Result

use of org.junit.runner.Result in project randomizedtesting by randomizedtesting.

the class TestJUnit3MethodProvider method testJUnit3Overrides.

@Test
public void testJUnit3Overrides() throws Exception {
    Result r = new JUnitCore().run(new RandomizedRunner(S3.class));
    Assert.assertEquals(0, r.getFailureCount());
    Assert.assertEquals(1, r.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 99 with Result

use of org.junit.runner.Result in project spring-boot by spring-projects.

the class Mockito110Tests method runTests.

private void runTests(Class<?> testClass) {
    Result result = new JUnitCore().run(testClass);
    for (Failure failure : result.getFailures()) {
        System.err.println(failure.getTrace());
    }
    assertThat(result.getFailureCount()).isEqualTo(0);
    assertThat(result.getRunCount()).isGreaterThan(0);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result)

Example 100 with Result

use of org.junit.runner.Result in project spring-boot by spring-projects.

the class Mockito21Tests method runTests.

private void runTests(Class<?> testClass) {
    Result result = new JUnitCore().run(testClass);
    for (Failure failure : result.getFailures()) {
        System.err.println(failure.getTrace());
    }
    assertThat(result.getFailureCount()).isEqualTo(0);
    assertThat(result.getRunCount()).isGreaterThan(0);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result)

Aggregations

Result (org.junit.runner.Result)337 Test (org.junit.Test)267 JUnitCore (org.junit.runner.JUnitCore)100 Failure (org.junit.runner.notification.Failure)90 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)61 UnitTest (org.apache.geode.test.junit.categories.UnitTest)56 Description (org.junit.runner.Description)28 Request (org.junit.runner.Request)22 TestResult (junit.framework.TestResult)21 RunListener (org.junit.runner.notification.RunListener)17 IOException (java.io.IOException)12 SettableCurrentRunningTest (com.google.testing.junit.runner.internal.junit4.SettableCurrentRunningTest)11 CurrentRunningTest (com.google.testing.junit.runner.util.CurrentRunningTest)11 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)9 ArrayList (java.util.ArrayList)7 Runner (org.junit.runner.Runner)7 ComparisonFailure (org.junit.ComparisonFailure)6 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 TextListener (org.junit.internal.TextListener)5 ShardingEnvironment (com.google.testing.junit.runner.sharding.ShardingEnvironment)4