Search in sources :

Example 6 with TestCase

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

the class PrettyFormatter method preCalculateLocationIndent.

private void preCalculateLocationIndent(TestCaseStarted event) {
    TestCase testCase = event.getTestCase();
    Integer longestStep = testCase.getTestSteps().stream().filter(PickleStepTestStep.class::isInstance).map(PickleStepTestStep.class::cast).map(PickleStepTestStep::getStep).map(step -> formatPlainStep(step.getKeyword(), step.getText()).length()).max(Comparator.naturalOrder()).orElse(0);
    int scenarioLength = formatScenarioDefinition(testCase).length();
    commentStartIndex.put(testCase.getId(), max(longestStep, scenarioLength) + 1);
}
Also used : PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCase(io.cucumber.plugin.event.TestCase)

Example 7 with TestCase

use of io.cucumber.plugin.event.TestCase in project syndesis-qe by syndesisio.

the class PrettyFormatter method printScenarioDefinition.

private void printScenarioDefinition(TestCaseStarted event) {
    TestCase testCase = event.getTestCase();
    String definitionText = formatScenarioDefinition(testCase);
    String path = relativize(testCase.getUri()).getSchemeSpecificPart();
    String locationIndent = calculateLocationIndent(event.getTestCase(), SCENARIO_INDENT + definitionText);
    out.println(SCENARIO_INDENT + definitionText + locationIndent + formatLocation(path + ":" + testCase.getLocation().getLine()));
}
Also used : TestCase(io.cucumber.plugin.event.TestCase)

Example 8 with TestCase

use of io.cucumber.plugin.event.TestCase in project syndesis-qe by syndesisio.

the class PrettyFormatter method preCalculateLocationIndent.

private void preCalculateLocationIndent(TestCaseStarted event) {
    TestCase testCase = event.getTestCase();
    Integer longestStep = testCase.getTestSteps().stream().filter(PickleStepTestStep.class::isInstance).map(PickleStepTestStep.class::cast).map(PickleStepTestStep::getStep).map(step -> formatPlainStep(step.getKeyword(), step.getText()).length()).max(Comparator.naturalOrder()).orElse(0);
    int scenarioLength = formatScenarioDefinition(testCase).length();
    commentStartIndex.put(testCase.getId(), max(longestStep, scenarioLength) + 1);
}
Also used : PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCase(io.cucumber.plugin.event.TestCase)

Example 9 with TestCase

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

the class EventBusTest method handlers_receive_the_events_they_registered_for.

@Test
void handlers_receive_the_events_they_registered_for() {
    EventHandler<TestStepFinished> handler = mock(EventHandler.class);
    PickleStepTestStep testStep = mock(PickleStepTestStep.class);
    Result result = new Result(Status.PASSED, ZERO, null);
    TestCase testCase = mock(TestCase.class);
    TestStepFinished event = new TestStepFinished(EPOCH, testCase, testStep, result);
    EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
    bus.registerHandlerFor(TestStepFinished.class, handler);
    bus.send(event);
    verify(handler).receive(event);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 10 with TestCase

use of io.cucumber.plugin.event.TestCase 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

TestCase (io.cucumber.plugin.event.TestCase)13 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)5 Location (io.cucumber.plugin.event.Location)3 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 EventBus (io.cucumber.core.eventbus.EventBus)2 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)2 EventPublisher (io.cucumber.plugin.event.EventPublisher)2 Node (io.cucumber.plugin.event.Node)2 Result (io.cucumber.plugin.event.Result)2 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)2 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)2 TestSourceParsed (io.cucumber.plugin.event.TestSourceParsed)2 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)2 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 CucumberException (io.cucumber.core.exception.CucumberException)1