Search in sources :

Example 6 with RunNotifier

use of org.junit.runner.notification.RunNotifier 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 7 with RunNotifier

use of org.junit.runner.notification.RunNotifier 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 8 with RunNotifier

use of org.junit.runner.notification.RunNotifier in project evosuite by EvoSuite.

the class SequenceExtractor method extractSequences.

/**
 * Extracts execution sequences from JUnit tests which are located in the given package with respect to the given target classes.
 *
 * @param packageToBeConsidered  package to be scanned for JUnit tests
 * @param targetClasses          classes for which sequences shall be extracted
 *
 * @return carved sequences (TestCase)
 */
public static List<TestCase> extractSequences(final String packageToBeConsidered, final Class<?>... targetClasses) {
    if (packageToBeConsidered == null) {
        throw new NullPointerException("Name of the package to be considered must not be null");
    }
    if (targetClasses == null || targetClasses.length == 0) {
        throw new IllegalArgumentException("No targets for sequence extraction specified");
    }
    final Collection<String> classes = getPossibleCandidates(packageToBeConsidered);
    final ArrayList<TestCase> carvedSequences = new ArrayList<TestCase>();
    CarvingTestRunner testRunner;
    Class<?> clazz;
    TestCase carvedSequence;
    for (final String className : classes) {
        try {
            clazz = Class.forName(Utils.getClassNameFromResourcePath(className));
            if (isJUnitTestClass(clazz)) {
                try {
                    testRunner = new CarvingTestRunner(clazz, targetClasses);
                    // TODO is test result interesting?
                    testRunner.run(new RunNotifier());
                    carvedSequence = testRunner.getCarvedTest();
                    if (carvedSequence == null) {
                        logger.warn("For some reason, no carving took place for test class " + className);
                    } else {
                        carvedSequences.add(carvedSequence);
                    }
                } catch (final InitializationError e) {
                    logger.error("An error occurred while initializing CarvingTestRunner for test class " + className, e);
                }
            }
        } catch (final Throwable e) {
            logger.error("Couldn't get class instance of class " + className, e);
        }
    }
    return carvedSequences;
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) TestCase(org.evosuite.testcase.TestCase) InitializationError(org.junit.runners.model.InitializationError) ArrayList(java.util.ArrayList)

Example 9 with RunNotifier

use of org.junit.runner.notification.RunNotifier in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method step_notification_can_be_turned_on_scenario_outline_with_two_examples_table_and_background.

@Test
void step_notification_can_be_turned_on_scenario_outline_with_two_examples_table_and_background() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Background: background\n" + "    Given step #1\n" + "  Scenario Outline: scenario <id>\n" + "    When step #2 \n" + "    Then step #3 \n" + "    Examples: examples 1 name\n" + "      | id | \n" + "      | #1 |\n" + "      | #2  |\n" + "    Examples: examples 2 name\n" + "      | id |\n" + "      | #3 |\n");
    JUnitOptions junitOption = new JUnitOptionsBuilder().setStepNotifications(true).build();
    RunNotifier notifier = runFeatureWithNotifier(feature, junitOption);
    InOrder order = inOrder(notifier);
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #1")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #1)")));
    order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #1)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #1)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #1)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #1)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #1)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #1)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #1)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #1)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #1")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #2")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #2)")));
    order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #2)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #2)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #2)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #2)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #2)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #2)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #2)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #2)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #2")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("scenario #3")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #1(scenario #3)")));
    order.verify(notifier).fireTestFailure(argThat(new FailureMatcher("step #1(scenario #3)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #1(scenario #3)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #2(scenario #3)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #2(scenario #3)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #2(scenario #3)")));
    order.verify(notifier).fireTestStarted(argThat(new DescriptionMatcher("step #3(scenario #3)")));
    order.verify(notifier).fireTestAssumptionFailed(argThat(new FailureMatcher("step #3(scenario #3)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("step #3(scenario #3)")));
    order.verify(notifier).fireTestFinished(argThat(new DescriptionMatcher("scenario #3")));
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) InOrder(org.mockito.InOrder) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 10 with RunNotifier

use of org.junit.runner.notification.RunNotifier in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop.

@Test
void should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario_1 name\n" + "    Given step #1\n");
    Filters filters = new Filters(RuntimeOptions.defaultOptions());
    IllegalStateException illegalStateException = new IllegalStateException();
    RunnerSupplier runnerSupplier = () -> {
        throw illegalStateException;
    };
    TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    RuntimeOptions options = RuntimeOptions.defaultOptions();
    CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
    FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
    RunNotifier notifier = mock(RunNotifier.class);
    PickleRunners.PickleRunner pickleRunner = featureRunner.getChildren().get(0);
    featureRunner.runChild(pickleRunner, notifier);
    Description description = pickleRunner.getDescription();
    ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
    InOrder order = inOrder(notifier);
    order.verify(notifier).fireTestStarted(description);
    order.verify(notifier).fireTestFailure(failureArgumentCaptor.capture());
    assertThat(failureArgumentCaptor.getValue().getException(), is(equalTo(illegalStateException)));
    assertThat(failureArgumentCaptor.getValue().getDescription(), is(equalTo(description)));
    order.verify(notifier).pleaseStop();
    order.verify(notifier).fireTestFinished(description);
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) Feature(io.cucumber.core.gherkin.Feature) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Failure(org.junit.runner.notification.Failure) Test(org.junit.jupiter.api.Test)

Aggregations

RunNotifier (org.junit.runner.notification.RunNotifier)53 Failure (org.junit.runner.notification.Failure)16 Description (org.junit.runner.Description)15 Test (org.junit.Test)14 RunListener (org.junit.runner.notification.RunListener)13 Test (org.junit.jupiter.api.Test)9 Runner (org.junit.runner.Runner)9 InOrder (org.mockito.InOrder)7 Feature (io.cucumber.core.gherkin.Feature)5 ArrayList (java.util.ArrayList)5 Before (org.junit.Before)5 Request (org.junit.runner.Request)5 Result (org.junit.runner.Result)5 ParentRunner (org.junit.runners.ParentRunner)4 HashMap (java.util.HashMap)3 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)3 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)3 KieSession (org.kie.api.runtime.KieSession)3 Match (gherkin.formatter.model.Match)2 Scenario (gherkin.formatter.model.Scenario)2