Search in sources :

Example 6 with TestStepFinished

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

the class UsageFormatterTest method resultWithPassedStep.

@Test
void resultWithPassedStep() {
    OutputStream out = new ByteArrayOutputStream();
    UsageFormatter usageFormatter = new UsageFormatter(out);
    TestStep testStep = mockTestStep();
    Result result = new Result(Status.PASSED, Duration.ofMillis(12345L), null);
    usageFormatter.handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, result));
    Map<String, List<UsageFormatter.StepContainer>> usageMap = usageFormatter.usageMap;
    assertThat(usageMap.size(), is(equalTo(1)));
    List<UsageFormatter.StepContainer> durationEntries = usageMap.get("stepDef");
    assertThat(durationEntries.size(), is(equalTo(1)));
    assertThat(durationEntries.get(0).getName(), is(equalTo("step")));
    assertThat(durationEntries.get(0).getDurations().size(), is(equalTo(1)));
    assertThat(durationEntries.get(0).getDurations().get(0).getDuration(), is(closeTo(12.345, EPSILON)));
}
Also used : TestStep(io.cucumber.plugin.event.TestStep) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 7 with TestStepFinished

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

the class UsageFormatterTest method resultWithNullDuration.

// Note: Duplicate of above test
@Test
void resultWithNullDuration() {
    OutputStream out = new ByteArrayOutputStream();
    UsageFormatter usageFormatter = new UsageFormatter(out);
    PickleStepTestStep testStep = mockTestStep();
    Result result = new Result(Status.PASSED, Duration.ZERO, null);
    usageFormatter.handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, result));
    Map<String, List<UsageFormatter.StepContainer>> usageMap = usageFormatter.usageMap;
    assertThat(usageMap.size(), is(equalTo(1)));
    List<UsageFormatter.StepContainer> durationEntries = usageMap.get("stepDef");
    assertThat(durationEntries.size(), is(equalTo(1)));
    assertThat(durationEntries.get(0).getName(), is(equalTo("step")));
    assertThat(durationEntries.get(0).getDurations().size(), is(equalTo(1)));
    assertThat(durationEntries.get(0).getDurations().get(0).getDuration(), is(equalTo(0.0)));
}
Also used : PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 8 with TestStepFinished

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

the class TestStep method emitTestStepFinished.

private void emitTestStepFinished(TestCase testCase, EventBus bus, UUID textExecutionId, Instant stopTime, Duration duration, Result result) {
    bus.send(new TestStepFinished(stopTime, testCase, this, result));
    TestStepResult testStepResult = new TestStepResult();
    if (result.getError() != null) {
        testStepResult.setMessage(extractStackTrace(result.getError()));
    }
    testStepResult.setStatus(from(result.getStatus()));
    testStepResult.setDuration(javaDurationToDuration(duration));
    Envelope envelope = new Envelope();
    envelope.setTestStepFinished(new io.cucumber.messages.types.TestStepFinished(textExecutionId.toString(), id.toString(), testStepResult, javaInstantToTimestamp(stopTime)));
    bus.send(envelope);
}
Also used : TestStepResult(io.cucumber.messages.types.TestStepResult) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) Envelope(io.cucumber.messages.types.Envelope)

Example 9 with TestStepFinished

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

the class JUnitReporterWithStepNotificationsTest method test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step.

@Test
void test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Result result = new Result(Status.SKIPPED, ZERO, null);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    verify(runNotifier).fireTestAssumptionFailed(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure stepFailure = failureArgumentCaptor.getValue();
    assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
    assertThat(stepFailure.getException(), instanceOf(SkippedThrowable.class));
    assertThat(stepFailure.getException().getMessage(), is(equalTo("This step is skipped")));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, times(2)).fireTestAssumptionFailed(failureArgumentCaptor.capture());
    Failure pickleFailure = failureArgumentCaptor.getValue();
    assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.getException(), instanceOf(SkippedThrowable.class));
    assertThat(pickleFailure.getException().getMessage(), is(equalTo("This scenario is skipped")));
}
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) Failure(org.junit.runner.notification.Failure) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 10 with TestStepFinished

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

the class JUnitReporterWithStepNotificationsTest method test_step_finished_fires_test_failure_and_test_finished_for_failed_hook.

@Test
void test_step_finished_fires_test_failure_and_test_finished_for_failed_hook() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Result stepResult = new Result(Status.PASSED, ZERO, null);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), stepResult));
    bus.send(new TestStepStarted(now(), testCase, mock(HookTestStep.class)));
    Throwable exception = new Exception("Oops");
    Result result = new Result(Status.FAILED, ZERO, exception);
    bus.send(new TestStepFinished(now(), testCase, mock(HookTestStep.class), result));
    // Hooks are not included in step failure
    verify(runNotifier, never()).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure pickleFailure = failureArgumentCaptor.getValue();
    assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.getException(), is(equalTo(exception)));
}
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) 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)

Aggregations

TestStepFinished (io.cucumber.plugin.event.TestStepFinished)33 Result (io.cucumber.plugin.event.Result)31 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)24 Test (org.junit.jupiter.api.Test)24 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)17 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)16 Test (org.testng.annotations.Test)8 Failure (org.junit.runner.notification.Failure)7 SkipException (org.testng.SkipException)7 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)6 Arrays.asList (java.util.Arrays.asList)6 Collections.singletonList (java.util.Collections.singletonList)6 List (java.util.List)6 UUID (java.util.UUID)6 EventBus (io.cucumber.core.eventbus.EventBus)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 CucumberException (io.cucumber.core.exception.CucumberException)4 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)4 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)4 TestCase (io.cucumber.plugin.event.TestCase)4