Search in sources :

Example 16 with TestCaseStarted

use of io.cucumber.plugin.event.TestCaseStarted in project cucumber-jvm by cucumber.

the class JUnitReporterWithStepNotificationsTest method test_case_finished_fires_test_finished_for_pickle.

@Test
void test_case_finished_fires_test_finished_for_pickle() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Result result = new Result(Status.PASSED, ZERO, null);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier).fireTestStarted(pickleRunner.describeChild(step));
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 17 with TestCaseStarted

use of io.cucumber.plugin.event.TestCaseStarted in project cucumber-jvm by cucumber.

the class JUnitReporterWithStepNotificationsTest method test_step_finished_fires_test_failure_and_test_finished_for_failed_step_with_multiple_failure_exception.

@Test
void test_step_finished_fires_test_failure_and_test_finished_for_failed_step_with_multiple_failure_exception() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    List<Throwable> failures = asList(new Exception("Oops"), new Exception("I did it again"));
    Throwable exception = new MultipleFailureException(failures);
    Result result = new Result(Status.FAILED, ZERO, exception);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    List<Failure> stepFailure = failureArgumentCaptor.getAllValues();
    assertThat(stepFailure.get(0).getDescription(), is(equalTo(pickleRunner.describeChild(step))));
    assertThat(stepFailure.get(0).getException(), is(equalTo(failures.get(0))));
    assertThat(stepFailure.get(1).getDescription(), is(equalTo(pickleRunner.describeChild(step))));
    assertThat(stepFailure.get(1).getException(), is(equalTo(failures.get(1))));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, times(4)).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    List<Failure> pickleFailure = failureArgumentCaptor.getAllValues();
    // Mockito recapture all arguments on .capture() so we end up with the
    // original 2, those 2 repeated and the finally the 2 we expect.
    assertThat(pickleFailure.get(4).getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.get(4).getException(), is(equalTo(failures.get(0))));
    assertThat(pickleFailure.get(5).getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.get(5).getException(), is(equalTo(failures.get(1))));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) MultipleFailureException(org.junit.runners.model.MultipleFailureException) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) MultipleFailureException(org.junit.runners.model.MultipleFailureException) AssumptionViolatedException(org.junit.AssumptionViolatedException) CucumberException(io.cucumber.core.exception.CucumberException) Failure(org.junit.runner.notification.Failure) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 18 with TestCaseStarted

use of io.cucumber.plugin.event.TestCaseStarted in project cucumber-jvm by cucumber.

the class TestCaseResultObserverTest method skippedByDryRun.

@Test
void skippedByDryRun() {
    bus.send(new TestCaseStarted(Instant.now(), testCase));
    bus.send(new TestStepStarted(Instant.now(), testCase, testStep));
    Result result = new Result(Status.SKIPPED, Duration.ZERO, null);
    bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
    bus.send(new TestCaseFinished(Instant.now(), testCase, result));
    Exception exception = assertThrows(Exception.class, observer::assertTestCasePassed);
    assertThat(exception.getCause(), instanceOf(TestAbortedException.class));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestAbortedException(org.opentest4j.TestAbortedException) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) TestAbortedException(org.opentest4j.TestAbortedException) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 19 with TestCaseStarted

use of io.cucumber.plugin.event.TestCaseStarted in project cucumber-jvm by cucumber.

the class TestCaseResultObserverTest method skippedByUser.

@Test
void skippedByUser() {
    bus.send(new TestCaseStarted(Instant.now(), testCase));
    bus.send(new TestStepStarted(Instant.now(), testCase, testStep));
    Result result = new Result(Status.SKIPPED, Duration.ZERO, new TestAbortedException("thrown by user"));
    bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
    bus.send(new TestCaseFinished(Instant.now(), testCase, result));
    Exception exception = assertThrows(Exception.class, observer::assertTestCasePassed);
    assertThat(exception.getCause(), instanceOf(TestAbortedException.class));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestAbortedException(org.opentest4j.TestAbortedException) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) TestAbortedException(org.opentest4j.TestAbortedException) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 20 with TestCaseStarted

use of io.cucumber.plugin.event.TestCaseStarted in project cucumber-jvm by cucumber.

the class TeamCityPlugin method printTestCaseStarted.

private void printTestCaseStarted(TestCaseStarted event) {
    TestCase testCase = event.getTestCase();
    URI uri = testCase.getUri();
    String timestamp = extractTimeStamp(event);
    Location location = testCase.getLocation();
    Predicate<Node> withLocation = candidate -> location.equals(candidate.getLocation());
    List<Node> path = parsedTestSources.get(uri).stream().map(node -> node.findPathTo(withLocation)).filter(Optional::isPresent).map(Optional::get).findFirst().orElse(emptyList());
    poppedNodes(path).forEach(node -> finishNode(timestamp, node));
    pushedNodes(path).forEach(node -> startNode(uri, timestamp, node));
    this.currentStack = path;
    this.currentTestCase = testCase;
    print(TEMPLATE_PROGRESS_TEST_STARTED, timestamp);
}
Also used : TestStepStarted(io.cucumber.plugin.event.TestStepStarted) ExceptionUtils.printStackTrace(io.cucumber.core.exception.ExceptionUtils.printStackTrace) ZonedDateTime(java.time.ZonedDateTime) TestStep(io.cucumber.plugin.event.TestStep) TestSourceParsed(io.cucumber.plugin.event.TestSourceParsed) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) HashMap(java.util.HashMap) Status(io.cucumber.plugin.event.Status) TestCase(io.cucumber.plugin.event.TestCase) Supplier(java.util.function.Supplier) EventListener(io.cucumber.plugin.EventListener) ArrayList(java.util.ArrayList) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Matcher(java.util.regex.Matcher) EmbedEvent(io.cucumber.plugin.event.EmbedEvent) WriteEvent(io.cucumber.plugin.event.WriteEvent) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) Locale(java.util.Locale) Map(java.util.Map) HookTestStep(io.cucumber.plugin.event.HookTestStep) URI(java.net.URI) ZoneOffset(java.time.ZoneOffset) Event(io.cucumber.plugin.event.Event) EventPublisher(io.cucumber.plugin.event.EventPublisher) PrintStream(java.io.PrintStream) Result(io.cucumber.plugin.event.Result) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Node(io.cucumber.plugin.event.Node) Location(io.cucumber.plugin.event.Location) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) HookType(io.cucumber.plugin.event.HookType) List(java.util.List) Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) Optional(java.util.Optional) TestCase(io.cucumber.plugin.event.TestCase) Node(io.cucumber.plugin.event.Node) URI(java.net.URI) Location(io.cucumber.plugin.event.Location)

Aggregations

TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)21 Test (org.junit.jupiter.api.Test)18 Result (io.cucumber.plugin.event.Result)16 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)16 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)16 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)15 Failure (org.junit.runner.notification.Failure)7 CucumberException (io.cucumber.core.exception.CucumberException)4 AssumptionViolatedException (org.junit.AssumptionViolatedException)4 TestAbortedException (org.opentest4j.TestAbortedException)4 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)3 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)3 MultipleFailureException (org.junit.runners.model.MultipleFailureException)3 Location (io.cucumber.plugin.event.Location)2 TestCase (io.cucumber.plugin.event.TestCase)2 EventBus (io.cucumber.core.eventbus.EventBus)1 ExceptionUtils.printStackTrace (io.cucumber.core.exception.ExceptionUtils.printStackTrace)1 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)1 Envelope (io.cucumber.messages.types.Envelope)1 EventListener (io.cucumber.plugin.EventListener)1