Search in sources :

Example 1 with TestStep

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

the class UnusedStepsSummaryPrinterTest method mockTestStep.

private static TestStep mockTestStep(String location) {
    TestStep testStep = mock(TestStep.class);
    when(testStep.getCodeLocation()).thenReturn(location);
    return testStep;
}
Also used : TestStep(io.cucumber.plugin.event.TestStep)

Example 2 with TestStep

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

the class UsageFormatterTest method resultWithPassedAndFailedStep.

@Test
void resultWithPassedAndFailedStep() {
    OutputStream out = new ByteArrayOutputStream();
    UsageFormatter usageFormatter = new UsageFormatter(out);
    TestStep testStep = mockTestStep();
    Result passed = new Result(Status.PASSED, Duration.ofSeconds(12345L), null);
    usageFormatter.handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, passed));
    Result failed = new Result(Status.FAILED, Duration.ZERO, null);
    usageFormatter.handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, failed));
    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(12345.0, 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 3 with TestStep

use of io.cucumber.plugin.event.TestStep 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 4 with TestStep

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

the class JUnitReporter method handTestStepStarted.

private void handTestStepStarted(TestStepStarted event) {
    TestStep testStep = event.getTestStep();
    if (testStep instanceof PickleStepTestStep) {
        PickleStepTestStep pickleStep = (PickleStepTestStep) testStep;
        if (junitOptions.stepNotifications()) {
            Description description = pickleRunner.describeChild(pickleStep.getStep());
            stepNotifier = new EachTestNotifier(runNotifier, description);
        } else {
            stepNotifier = new NoTestNotifier();
        }
        stepNotifier.fireTestStarted();
    }
}
Also used : TestStep(io.cucumber.plugin.event.TestStep) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) Description(org.junit.runner.Description)

Example 5 with TestStep

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

the class JsonFormatter method createTestStep.

private Map<String, Object> createTestStep(PickleStepTestStep testStep) {
    Map<String, Object> stepMap = new HashMap<>();
    stepMap.put("name", testStep.getStepText());
    stepMap.put("line", testStep.getStepLine());
    TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testStep.getStepLine());
    StepArgument argument = testStep.getStepArgument();
    if (argument != null) {
        if (argument instanceof DocStringArgument) {
            DocStringArgument docStringArgument = (DocStringArgument) argument;
            stepMap.put("doc_string", createDocStringMap(docStringArgument));
        } else if (argument instanceof DataTableArgument) {
            DataTableArgument dataTableArgument = (DataTableArgument) argument;
            stepMap.put("rows", createDataTableList(dataTableArgument));
        }
    }
    if (astNode != null) {
        Step step = (Step) astNode.node;
        stepMap.put("keyword", step.getKeyword());
    }
    return stepMap;
}
Also used : StepArgument(io.cucumber.plugin.event.StepArgument) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DataTableArgument(io.cucumber.plugin.event.DataTableArgument) TestStep(io.cucumber.plugin.event.TestStep) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) HookTestStep(io.cucumber.plugin.event.HookTestStep) Step(io.cucumber.messages.types.Step) DocStringArgument(io.cucumber.plugin.event.DocStringArgument)

Aggregations

TestStep (io.cucumber.plugin.event.TestStep)6 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)5 Result (io.cucumber.plugin.event.Result)3 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3 Arrays.asList (java.util.Arrays.asList)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Test (org.junit.jupiter.api.Test)3 Step (io.cucumber.messages.types.Step)1 DataTableArgument (io.cucumber.plugin.event.DataTableArgument)1 DocStringArgument (io.cucumber.plugin.event.DocStringArgument)1 HookTestStep (io.cucumber.plugin.event.HookTestStep)1 StepArgument (io.cucumber.plugin.event.StepArgument)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Description (org.junit.runner.Description)1