Skip to content

[Core] Include all fields in JsonFormatters failure feature #1954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>io.cucumber:gherkin</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>gherkin</pattern>
<shadedPattern>io.cucumber.core.internal.gherkin</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
76 changes: 66 additions & 10 deletions core/src/main/java/io/cucumber/core/plugin/JsonFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static io.cucumber.core.exception.ExceptionUtils.printStackTrace;
import static java.util.Collections.singletonList;
import static java.util.Locale.ROOT;
import static java.util.stream.Collectors.toList;

Expand Down Expand Up @@ -140,16 +142,7 @@ private void handleTestStepFinished(TestStepFinished event) {
private void finishReport(TestRunFinished event) {
Throwable exception = event.getResult().getError();
if (exception != null) {
Map<String, Object> feature = new LinkedHashMap<>();
feature.put("description", "Test run failed");
Map<String, Object> elements = new LinkedHashMap<>();
feature.put("elements", elements);
elements.put("description", "There were errors during the execution");
Map<String, Object> result = new LinkedHashMap<>();
elements.put("result", result);
result.put("error_message", exception.getMessage());
result.put("status", "failed");
featureMaps.add(feature);
featureMaps.add(createDummyFeatureForFailure(event));
}

gson.toJson(featureMaps, out);
Expand All @@ -160,6 +153,69 @@ private void finishReport(TestRunFinished event) {
}
}

private Map<String, Object> createDummyFeatureForFailure(TestRunFinished event) {
Throwable exception = event.getResult().getError();

Map<String, Object> feature = new LinkedHashMap<>();
feature.put("line", 1);
{
Map<String, Object> scenario = new LinkedHashMap<>();
feature.put("elements", singletonList(scenario));

scenario.put("start_timestamp", getDateTimeFromTimeStamp(event.getInstant()));
scenario.put("line", 2);
scenario.put("name", "Could not execute Cucumber");
scenario.put("description", "");
scenario.put("id", "failure;could-not-execute-cucumber");
scenario.put("type", "scenario");
scenario.put("keyword", "Scenario");

Map<String, Object> when = new LinkedHashMap<>();
Map<String, Object> then = new LinkedHashMap<>();
scenario.put("steps", Arrays.asList(when, then));
{

{
Map<String, Object> whenResult = new LinkedHashMap<>();
when.put("result", whenResult);
whenResult.put("duration", 0);
whenResult.put("status", "passed");
}
when.put("line", 3);
when.put("name", "Cucumber could not execute");
Map<String, Object> whenMatch = new LinkedHashMap<>();
when.put("match", whenMatch);
whenMatch.put("arguments", new ArrayList<>());
whenMatch.put("location", "io.cucumber.core.Failure.cucumber_could_not_execute()");
when.put("keyword", "When ");

{
Map<String, Object> thenResult = new LinkedHashMap<>();
then.put("result", thenResult);
thenResult.put("duration", 0);
thenResult.put("error_message", exception.getMessage());
thenResult.put("status", "failed");
}
then.put("line", 4);
then.put("name", "Cucumber will report this error:");
Map<String, Object> thenMatch = new LinkedHashMap<>();
then.put("match", thenMatch);
thenMatch.put("arguments", new ArrayList<>());
thenMatch.put("location", "io.cucumber.core.Failure.cucumber_reports_this_error()");
then.put("keyword", "Then ");
}

feature.put("name", "Test run failed");
feature.put("description", "There were errors during the execution");
feature.put("id", "failure");
feature.put("keyword", "Feature");
feature.put("uri", "classpath:io/cucumber/core/failure.feature");
feature.put("tags", new ArrayList<>());
}

return feature;
}

private Map<String, Object> createFeatureMap(TestCase testCase) {
Map<String, Object> featureMap = new HashMap<>();
featureMap.put("uri", TestSourcesModel.relativize(testCase.getUri()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static Supplier<Type> stepDefinitionDoesNotTakeAnyParameter(StepDefiniti
private CucumberException registerTypeInConfiguration(String expressionString, UndefinedParameterTypeException e) {
return new CucumberException(format("" +
"Could not create a cucumber expression for '%s'.\n" +
"It appears you did not register parameter type.",
"It appears you did not register a parameter type.",
expressionString
), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void throws_for_unknown_parameter_types() {
);
assertThat(exception.getMessage(), is("" +
"Could not create a cucumber expression for 'Given a {unknownParameterType}'.\n" +
"It appears you did not register parameter type."
"It appears you did not register a parameter type."

));
assertThat(events, iterableWithSize(1));
Expand Down