Search in sources :

Example 51 with Result

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

the class TestCase method run.

void run(EventBus bus) {
    ExecutionMode nextExecutionMode = this.executionMode;
    emitTestCaseMessage(bus);
    Instant start = bus.getInstant();
    UUID executionId = bus.generateId();
    emitTestCaseStarted(bus, start, executionId);
    TestCaseState state = new TestCaseState(bus, executionId, this);
    for (HookTestStep before : beforeHooks) {
        nextExecutionMode = before.run(this, bus, state, executionMode).next(nextExecutionMode);
    }
    for (PickleStepTestStep step : testSteps) {
        nextExecutionMode = step.run(this, bus, state, nextExecutionMode).next(nextExecutionMode);
    }
    for (HookTestStep after : afterHooks) {
        nextExecutionMode = after.run(this, bus, state, executionMode).next(nextExecutionMode);
    }
    Instant stop = bus.getInstant();
    Duration duration = Duration.between(start, stop);
    Status status = Status.valueOf(state.getStatus().name());
    Result result = new Result(status, duration, state.getError());
    emitTestCaseFinished(bus, executionId, stop, duration, status, result);
}
Also used : Status(io.cucumber.plugin.event.Status) Instant(java.time.Instant) TimeConversion.javaDurationToDuration(io.cucumber.messages.TimeConversion.javaDurationToDuration) Duration(java.time.Duration) UUID(java.util.UUID) TestStepResult(io.cucumber.messages.types.TestStepResult) Result(io.cucumber.plugin.event.Result)

Example 52 with Result

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

the class TestCaseResultObserverTest method should_not_be_passed_for_ambiguous_result.

@Test
public void should_not_be_passed_for_ambiguous_result() {
    TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
    Result stepResult = new Result(AMBIGUOUS, ZERO, error);
    bus.send(new TestStepFinished(now(), testCase, step, stepResult));
    Result testCaseResult = new Result(AMBIGUOUS, ZERO, error);
    bus.send(new TestCaseFinished(now(), testCase, testCaseResult));
    Exception exception = expectThrows(Exception.class, resultListener::assertTestCasePassed);
    assertEquals(exception.getCause(), error);
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) SkipException(org.testng.SkipException) Result(io.cucumber.plugin.event.Result) Test(org.testng.annotations.Test)

Example 53 with Result

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

the class TestCaseResultObserverTest method should_be_passed_for_passed_result.

@Test
public void should_be_passed_for_passed_result() {
    TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
    Result stepResult = new Result(Status.PASSED, ZERO, null);
    bus.send(new TestStepFinished(now(), testCase, step, stepResult));
    Result testCaseResult = new Result(Status.PASSED, ZERO, null);
    bus.send(new TestCaseFinished(now(), testCase, testCaseResult));
    resultListener.assertTestCasePassed();
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) Result(io.cucumber.plugin.event.Result) Test(org.testng.annotations.Test)

Example 54 with Result

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

the class TestCaseResultObserverTest method should_not_be_skipped_for_pending_result.

@Test
public void should_not_be_skipped_for_pending_result() {
    TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
    TestPendingException error = new TestPendingException();
    Result stepResult = new Result(PENDING, ZERO, error);
    bus.send(new TestStepFinished(now(), testCase, step, stepResult));
    Result testCaseResult = new Result(PENDING, ZERO, error);
    bus.send(new TestCaseFinished(now(), testCase, testCaseResult));
    Exception exception = expectThrows(Exception.class, resultListener::assertTestCasePassed);
    assertEquals(exception.getCause(), error);
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) SkipException(org.testng.SkipException) Result(io.cucumber.plugin.event.Result) Test(org.testng.annotations.Test)

Example 55 with Result

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

the class UsageFormatterTest method resultWithZeroDuration.

@Test
void resultWithZeroDuration() {
    OutputStream out = new ByteArrayOutputStream();
    UsageFormatter usageFormatter = new UsageFormatter(out);
    TestStep 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 : 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)

Aggregations

Result (io.cucumber.plugin.event.Result)56 Test (org.junit.jupiter.api.Test)41 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)29 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)26 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)15 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)14 Test (org.testng.annotations.Test)9 UUID (java.util.UUID)7 Failure (org.junit.runner.notification.Failure)7 SkipException (org.testng.SkipException)7 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)6 Status (io.cucumber.plugin.event.Status)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 List (java.util.List)6 TestAbortedException (org.opentest4j.TestAbortedException)6 EventBus (io.cucumber.core.eventbus.EventBus)5 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)5 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)5 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)5 OutputStream (java.io.OutputStream)5