Skip to content

Commit

Permalink
feat(Issue-1625): process aborted status in asciidoc report
Browse files Browse the repository at this point in the history
  • Loading branch information
l-1squared committed Aug 9, 2024
1 parent 57be682 commit 00ba4da
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public String convertStatisticsBlock(final ListMultimap<String, ReportStatistics
statisticsTable.append("| successful scenarios ");
statisticsTable.append("| failed scenarios ");
statisticsTable.append("| pending scenarios ");
statisticsTable.append("| aborted scenarios ");
statisticsTable.append("| total scenarios ");
statisticsTable.append("| failed cases ");
statisticsTable.append("| total cases ");
Expand Down Expand Up @@ -68,6 +69,8 @@ public String convertFeatureHeaderBlock(final String featureName, final ReportSt
.append(statistics.numFailedScenarios).append(" Failed, ");
blockContent.append(MetadataMapper.toHumanReadableStatus(ExecutionStatus.SCENARIO_PENDING)).append(" ")
.append(statistics.numPendingScenarios).append(" Pending, ");
blockContent.append(MetadataMapper.toHumanReadableStatus(ExecutionStatus.ABORTED)).append(" ")
.append(statistics.numAbortedScenarios).append(" Aborted, ");
blockContent.append(statistics.numScenarios).append(" Total");
blockContent.append(" (").append(MetadataMapper.toHumanReadableScenarioDuration(statistics.durationInNanos))
.append(")");
Expand Down Expand Up @@ -326,6 +329,7 @@ private static void appendStatisticsRowFragment(final StringBuilder builder, fin
builder.append(" | ").append(statistics.numSuccessfulScenarios);
builder.append(" | ").append(statistics.numFailedScenarios);
builder.append(" | ").append(statistics.numPendingScenarios);
builder.append(" | ").append(statistics.numAbortedScenarios);
builder.append(" | ").append(statistics.numScenarios);
builder.append(" | ").append(statistics.numFailedCases);
builder.append(" | ").append(statistics.numCases);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class AsciiDocReportGenerator extends AbstractReportGenerator {
private final List<String> featureFiles = new ArrayList<>();
private final List<String> failedScenarioFiles = new ArrayList<>();
private final List<String> pendingScenarioFiles = new ArrayList<>();
private final List<String> abortedScenarioFiles = new ArrayList<>();
private File targetDir;
private File featuresDir;

Expand Down Expand Up @@ -73,6 +74,8 @@ public void generate() {

writeIndexFileForPendingScenarios();

writeIndexFileForAbortedScenarios();

writeTotalStatisticsFile();

writeIndexFileForFullReport(config.getTitle());
Expand Down Expand Up @@ -115,6 +118,9 @@ private List<String> collectReportBlocks(final ReportModelFile reportModelFile,
if (statistics.numPendingScenarios > 0) {
pendingScenarioFiles.add(featureFileName);
}
if (statistics.numAbortedScenarios >0){
abortedScenarioFiles.add(featureFileName);
}

final AsciiDocReportModelVisitor visitor = new AsciiDocReportModelVisitor(blockConverter, statistics);
reportModelFile.model().accept(visitor);
Expand Down Expand Up @@ -151,6 +157,16 @@ private void writeIndexFileForPendingScenarios() {
snippetGenerator.generateIndexSnippet());
}

private void writeIndexFileForAbortedScenarios() {
final String scenarioKind = "aborted";
final AsciiDocSnippetGenerator snippetGenerator = new AsciiDocSnippetGenerator(
"Aborted Scenarios", "aborted scenarios", this.abortedScenarioFiles, scenarioKind,
this.completeReportModel.getTotalStatistics().numAbortedScenarios);

writeAsciiDocBlocksToFile(new File(targetDir, scenarioKind + "Scenarios.asciidoc"),
snippetGenerator.generateIndexSnippet());
}

private void writeTotalStatisticsFile() {

final ListMultimap<String, ReportStatistics> featureStatistics = completeReportModel.getAllReportModels()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class ReportStatistics {
public int numScenarios;
public int numFailedScenarios;
public int numPendingScenarios;
public int numAbortedScenarios;
public int numSuccessfulScenarios;
public int numCases;
public int numFailedCases;
Expand All @@ -23,6 +24,7 @@ private void addModifying( ReportStatistics statistics ) {
this.numScenarios += statistics.numScenarios;
this.numFailedScenarios += statistics.numFailedScenarios;
this.numPendingScenarios += statistics.numPendingScenarios;
this.numAbortedScenarios += statistics.numAbortedScenarios;
this.numSuccessfulScenarios += statistics.numSuccessfulScenarios;
this.numCases += statistics.numCases;
this.numFailedCases += statistics.numFailedCases;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public void visit( ScenarioModel scenarioModel ) {
statistics.numFailedScenarios += 1;
} else if( executionStatus == ExecutionStatus.SCENARIO_PENDING || executionStatus == ExecutionStatus.SOME_STEPS_PENDING) {
statistics.numPendingScenarios += 1;
} else if (executionStatus == ExecutionStatus.ABORTED){
statistics.numAbortedScenarios += 1;
} else {
statistics.numSuccessfulScenarios += 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,45 @@ public class AsciiDocFeatureBlockConverterTest {
public void convert_feature_header_without_description() {
// given
final ReportStatistics statistics = new ReportStatistics();
statistics.numScenarios = 42;
statistics.numScenarios = 47;
statistics.numFailedScenarios = 21;
statistics.numPendingScenarios = 13;
statistics.numAbortedScenarios = 5;
statistics.numSuccessfulScenarios = 8;

// when
final String block = converter.convertFeatureHeaderBlock("My first feature", statistics, null);

// then
assertThatBlockContainsLines(block,
"=== My first feature",
"",
"icon:check-square[role=green] 8 Successful, icon:exclamation-circle[role=red] 21 Failed, "
+ "icon:ban[role=silver] 13 Pending, 42 Total (0ms)");
"=== My first feature",
"",
"icon:check-square[role=green] 8 Successful, icon:exclamation-circle[role=red] 21 Failed, "
+ "icon:ban[role=silver] 13 Pending, icon:times-circle[role=gray] 5 Aborted, 47 Total (0ms)");
}

@Test
public void convert_feature_header_with_description() {
// given
final ReportStatistics statistics = new ReportStatistics();
statistics.numScenarios = 42;
statistics.numScenarios = 47;
statistics.numFailedScenarios = 21;
statistics.numPendingScenarios = 13;
statistics.numAbortedScenarios = 5;
statistics.numSuccessfulScenarios = 8;

// when
final String block =
converter.convertFeatureHeaderBlock("My first feature", statistics, "A very nice feature.");
converter.convertFeatureHeaderBlock("My first feature", statistics, "A very nice feature.");

// then
assertThatBlockContainsLines(block,
"=== My first feature",
"",
"icon:check-square[role=green] 8 Successful, icon:exclamation-circle[role=red] 21 Failed, "
+ "icon:ban[role=silver] 13 Pending, 42 Total (0ms)",
"",
"+++A very nice feature.+++");
"=== My first feature",
"",
"icon:check-square[role=green] 8 Successful, icon:exclamation-circle[role=red] 21 Failed, "
+ "icon:ban[role=silver] 13 Pending, icon:times-circle[role=gray] 5 Aborted, 47 Total (0ms)",
"",
"+++A very nice feature.+++");
}

private static void assertThatBlockContainsLines(final String block, final String... expectedLines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public void convert_statistics() {
statisticsOne.numScenarios = 3;
statisticsOne.numSuccessfulScenarios = 2;
statisticsOne.numFailedScenarios = 1;
statisticsOne.numAbortedScenarios = 3;
statisticsOne.numCases = 3;
statisticsOne.numFailedCases = 1;
statisticsOne.numSteps = 13;
Expand All @@ -149,6 +150,7 @@ public void convert_statistics() {
totalStatistics.numSuccessfulScenarios = 3;
totalStatistics.numPendingScenarios = 1;
totalStatistics.numFailedScenarios = 1;
totalStatistics.numAbortedScenarios = 3;
totalStatistics.numCases = 5;
totalStatistics.numFailedCases = 1;
totalStatistics.numSteps = 21;
Expand All @@ -166,11 +168,11 @@ public void convert_statistics() {
".Total Statistics",
"[.jg-statisticsTable%autowidth%header%footer]",
"|===",
"| feature | total classes | successful scenarios | failed scenarios | pending scenarios | "
+ "total scenarios | failed cases | total cases | total steps | duration",
"| Feature One | 1 | 2 | 1 | 0 | 3 | 1 | 3 | 13 | 0ms",
"| Feature Two | 1 | 1 | 0 | 1 | 2 | 1 | 2 | 8 | 0ms",
"| sum | 2 | 3 | 1 | 1 | 5 | 1 | 5 | 21 | 0ms",
"| feature | total classes | successful scenarios | failed scenarios | pending scenarios | aborted scenarios "
+ "| total scenarios | failed cases | total cases | total steps | duration",
"| Feature One | 1 | 2 | 1 | 0 | 3 | 3 | 1 | 3 | 13 | 0ms",
"| Feature Two | 1 | 1 | 0 | 1 | 0 | 2 | 1 | 2 | 8 | 0ms",
"| sum | 2 | 3 | 1 | 1 | 3 | 5 | 1 | 5 | 21 | 0ms",
"|===");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class JGivenPluginShould extends Specification {
repositories { mavenCentral() }
dependencies {
testImplementation 'com.tngtech.jgiven:jgiven-junit:1.2.5'
testImplementation 'com.tngtech.jgiven:jgiven-junit:1.3.1'
testImplementation 'junit:junit:4.13.2'
}
"""
Expand Down Expand Up @@ -59,7 +59,7 @@ class JGivenPluginShould extends Specification {
repositories { mavenCentral() }
dependencies {
testImplementation 'com.tngtech.jgiven:jgiven-junit:1.2.5'
testImplementation 'com.tngtech.jgiven:jgiven-junit:1.3.1'
testImplementation 'junit:junit:4.13.2'
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void setup() {
Given the_plugin_is_applied() throws IOException {
buildFile.write("plugins { id 'java'; id 'com.tngtech.jgiven.gradle-plugin' }\n");
buildFile.write("repositories { mavenCentral() }\n");
buildFile.write("dependencies { testImplementation 'com.tngtech.jgiven:jgiven-junit:1.2.5' }\n");
buildFile.write("dependencies { testImplementation 'com.tngtech.jgiven:jgiven-junit:1.3.1' }\n");
buildFile.write("dependencies { testImplementation 'junit:junit:4.13.2' }\n");
return self();
}
Expand Down

0 comments on commit 00ba4da

Please sign in to comment.