Search in sources :

Example 11 with RunListener

use of org.junit.runner.notification.RunListener in project n4js by eclipse.

the class XpectConfigurationDelegate method execute.

/**
 * Runs provided File in Engine. Returns output of execution.
 */
public void execute(ILaunch launch, XpectRunConfiguration runConfiguration) throws RuntimeException {
    Job job = new Job(launch.getLaunchConfiguration().getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            XpectRunner xr;
            try {
                xr = new XpectRunner(N4IDEXpectTestClass.class);
            } catch (InitializationError e) {
                N4IDEXpectUIPlugin.logError("cannot initialize xpect runner", e);
                return Status.CANCEL_STATUS;
            }
            // TODO support multiple selection
            /*
				 * if Project provided, or package files should be discovered there. Also multiple selected files
				 */
            String testFileLocation = runConfiguration.getXtFileToRun();
            IXpectURIProvider uriprov = xr.getUriProvider();
            if (uriprov instanceof N4IDEXpectTestURIProvider) {
                ((N4IDEXpectTestURIProvider) uriprov).addTestFileLocation(testFileLocation);
            }
            Result result = new Result();
            RunNotifier notifier = new RunNotifier();
            RunListener listener = result.createListener();
            N4IDEXpectRunListener n4Listener = new N4IDEXpectRunListener();
            notifier.addFirstListener(listener);
            notifier.addListener(n4Listener);
            try {
                notifier.fireTestRunStarted(xr.getDescription());
                xr.run(notifier);
                notifier.fireTestRunFinished(result);
            } finally {
                notifier.removeListener(n4Listener);
                notifier.removeListener(listener);
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) N4IDEXpectRunListener(org.eclipse.n4js.xpect.ui.results.N4IDEXpectRunListener) N4IDEXpectTestURIProvider(org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider) RunNotifier(org.junit.runner.notification.RunNotifier) N4IDEXpectTestClass(org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestClass) InitializationError(org.junit.runners.model.InitializationError) XpectRunner(org.eclipse.xpect.runner.XpectRunner) Job(org.eclipse.core.runtime.jobs.Job) IXpectURIProvider(org.eclipse.xpect.runner.IXpectURIProvider) Result(org.junit.runner.Result) N4IDEXpectRunListener(org.eclipse.n4js.xpect.ui.results.N4IDEXpectRunListener) RunListener(org.junit.runner.notification.RunListener)

Example 12 with RunListener

use of org.junit.runner.notification.RunListener in project ant by apache.

the class CustomJUnit4TestAdapterCache method getNotifier.

public RunNotifier getNotifier(final TestResult result) {
    final IgnoredTestResult resultWrapper = (IgnoredTestResult) result;
    RunNotifier notifier = new RunNotifier();
    notifier.addListener(new RunListener() {

        @Override
        public void testFailure(Failure failure) throws Exception {
            result.addError(asTest(failure.getDescription()), failure.getException());
        }

        @Override
        public void testFinished(Description description) throws Exception {
            result.endTest(asTest(description));
        }

        @Override
        public void testStarted(Description description) throws Exception {
            result.startTest(asTest(description));
        }

        @Override
        public void testIgnored(Description description) throws Exception {
            if (resultWrapper != null) {
                resultWrapper.testIgnored(asTest(description));
            }
        }

        @Override
        public void testAssumptionFailure(Failure failure) {
            if (resultWrapper != null) {
                resultWrapper.testAssumptionFailure(asTest(failure.getDescription()), failure.getException());
            }
        }
    });
    return notifier;
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 13 with RunListener

use of org.junit.runner.notification.RunListener in project randomizedtesting by randomizedtesting.

the class RandomizedRunner method subscribeListeners.

/**
 * Subscribe annotation listeners to the notifier.
 */
private void subscribeListeners(RunNotifier notifier) {
    for (Listeners ann : getAnnotationsFromClassHierarchy(suiteClass, Listeners.class)) {
        for (Class<? extends RunListener> clazz : ann.value()) {
            try {
                RunListener listener = clazz.newInstance();
                autoListeners.add(listener);
                notifier.addListener(listener);
            } catch (Throwable t) {
                throw new RuntimeException("Could not initialize suite class: " + suiteClass.getName() + " because its @Listener is not instantiable: " + clazz.getName(), t);
            }
        }
    }
}
Also used : Listeners(com.carrotsearch.randomizedtesting.annotations.Listeners) RunListener(org.junit.runner.notification.RunListener)

Example 14 with RunListener

use of org.junit.runner.notification.RunListener 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);
            }
        }
        final List<TestCandidate> tests = testCandidates;
        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 (isAssumptionViolated(t)) {
                        // 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 : 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 15 with RunListener

use of org.junit.runner.notification.RunListener in project randomizedtesting by randomizedtesting.

the class TestSeedParameterOptional method checkNames.

@Test
public void checkNames() {
    final HashSet<String> tests = new HashSet<String>();
    JUnitCore junit = new JUnitCore();
    junit.addListener(new RunListener() {

        @Override
        public void testStarted(Description description) throws Exception {
            tests.add(description.getMethodName());
        }
    });
    junit.run(Nested.class);
    // Single repetitions, no seed parameter in test name.
    Assert.assertTrue(tests.contains("method2"));
    Assert.assertTrue(tests.contains("method3"));
    // Method 1 has 2x3 repetitions.
    int count = 0;
    for (String s : tests) {
        if (s.startsWith("method1")) {
            count++;
        }
    }
    Assert.assertEquals(6, count);
}
Also used : HashSet(java.util.HashSet) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Aggregations

RunListener (org.junit.runner.notification.RunListener)51 Failure (org.junit.runner.notification.Failure)25 Description (org.junit.runner.Description)21 JUnitCore (org.junit.runner.JUnitCore)20 Result (org.junit.runner.Result)19 Test (org.junit.Test)18 RunNotifier (org.junit.runner.notification.RunNotifier)13 Request (org.junit.runner.Request)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)3 TextListener (org.junit.internal.TextListener)3 KieSession (org.kie.api.runtime.KieSession)3 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2 HashMap (java.util.HashMap)2 ScenarioUtil.failureToFailure (org.drools.workbench.screens.testscenario.backend.server.ScenarioUtil.failureToFailure)2