com.github.mkolisnyk.cucumber.reporting.CucumberCoverageOverview Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-report-generator Show documentation
Show all versions of cucumber-report-generator Show documentation
The part of the Cucumber Reports library directly responsible for
reports generation.
package com.github.mkolisnyk.cucumber.reporting;
import java.io.IOException;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import com.github.mkolisnyk.cucumber.reporting.types.enums.CucumberReportLink;
import com.github.mkolisnyk.cucumber.reporting.types.enums.CucumberReportTypes;
import com.github.mkolisnyk.cucumber.reporting.types.result.CucumberFeatureResult;
import com.github.mkolisnyk.cucumber.reporting.types.result.CucumberScenarioResult;
import com.github.mkolisnyk.cucumber.reporting.types.result.CucumberStepResult;
import com.github.mkolisnyk.cucumber.reporting.utils.drawers.PieChartDrawer;
import com.github.mkolisnyk.cucumber.runner.runtime.ExtendedRuntimeOptions;
public class CucumberCoverageOverview extends CucumberResultsOverview {
public CucumberCoverageOverview() {
super();
}
public CucumberCoverageOverview(ExtendedRuntimeOptions extendedOptions) {
super(extendedOptions);
this.setExcludeCoverageTags(extendedOptions.getExcludeCoverageTags());
this.setIncludeCoverageTags(extendedOptions.getIncludeCoverageTags());
}
private String[] includeCoverageTags = {};
private String[] excludeCoverageTags = {};
public final String[] getIncludeCoverageTags() {
return includeCoverageTags;
}
public final void setIncludeCoverageTags(String[] includeCoverageTagsValue) {
if (includeCoverageTagsValue == null) {
this.includeCoverageTags = new String[0];
} else {
this.includeCoverageTags = includeCoverageTagsValue;
}
}
public final String[] getExcludeCoverageTags() {
return excludeCoverageTags;
}
public final void setExcludeCoverageTags(String[] excludeCoverageTagsValue) {
if (excludeCoverageTagsValue == null) {
this.excludeCoverageTags = new String[0];
} else {
this.excludeCoverageTags = excludeCoverageTagsValue;
}
}
private String getFeatureStatus(CucumberFeatureResult result) {
if (result.getStatus().equals("undefined") || result.getUndefined() > 0) {
return "undefined";
} else {
return "passed";
}
}
private String getScenarioStatus(CucumberScenarioResult result) {
if (result.getStatus().equals("undefined") || result.getUndefined() > 0) {
return "undefined";
} else {
return "passed";
}
}
public int[][] getStatuses(CucumberFeatureResult[] results) {
int[][] statuses = {{0, 0}, {0, 0}, {0, 0}};
for (CucumberFeatureResult result : results) {
result.setIncludeCoverageTags(includeCoverageTags);
result.setExcludeCoverageTags(excludeCoverageTags);
if (result.getStatus().equals("undefined") || result.getUndefined() > 0) {
statuses[0][1]++;
} else {
statuses[0][0]++;
}
for (CucumberScenarioResult element : result.getElements()) {
element.setIncludeCoverageTags(includeCoverageTags);
element.setExcludeCoverageTags(excludeCoverageTags);
if (element.getStatus().equals("undefined") || element.getUndefined() > 0) {
statuses[1][1]++;
} else {
statuses[1][0]++;
}
for (CucumberStepResult step : element.getSteps()) {
if (step.getResult().getStatus().equals("undefined")) {
statuses[2][1]++;
} else {
statuses[2][0]++;
}
}
}
}
return statuses;
}
@Override
protected String generateFeatureOverview(CucumberFeatureResult[] results)
throws IOException {
String content = this.getReportBase();
content = content.replaceAll("__TITLE__", "Test Coverage Overview");
String reportContent = "";
reportContent += "Features Status
"
+ "Feature Name Status "
+ "Scenarios Tags "
+ "Covered Not Covered ";
for (CucumberFeatureResult result : results) {
result.setIncludeCoverageTags(includeCoverageTags);
result.setExcludeCoverageTags(excludeCoverageTags);
String status = getFeatureStatus(result);
reportContent += String.format(
Locale.US,
"%s %s %d %d %s ",
status,
result.getName(),
status,
result.getPassed() + result.getFailed() + result.getSkipped(),
result.getUndefined(),
StringUtils.join(result.getAllTags(true), ", "));
}
reportContent += "
";
reportContent += "Scenario Status
"
+ "Feature Name "
+ "Scenario "
+ "Status "
+ "Steps Tags "
+ "Covered "
+ "Not Covered ";
int[][] statuses = this.getStatuses(results);
int[] featureStatuses = statuses[0];
int[] scenarioStatuses = statuses[1];
for (CucumberFeatureResult result : results) {
result.setIncludeCoverageTags(includeCoverageTags);
result.setExcludeCoverageTags(excludeCoverageTags);
for (CucumberScenarioResult element : result.getElements()) {
element.setIncludeCoverageTags(includeCoverageTags);
element.setExcludeCoverageTags(excludeCoverageTags);
String status = getScenarioStatus(element);
Set tags = new HashSet();
for (String tag : result.getAllTags(false)) {
tags.add(tag);
}
for (String tag : element.getAllTags()) {
if (!tags.contains(tag)) {
tags.add(tag);
}
}
reportContent += String.format(
Locale.US,
""
+ "%s %s %s "
+ "%d %d %s ",
status,
result.getName(),
element.getName(),
status,
element.getPassed() + element.getFailed() + element.getSkipped(),
element.getUndefined(),
StringUtils.join(tags, ", "));
}
reportContent += " ";
}
reportContent += "
";
content = content.replaceAll("__REPORT__", reportContent);
PieChartDrawer pieChart = new PieChartDrawer();
content = content.replaceAll("__FEATURE_DATA__", pieChart.generatePieChart(
CHART_WIDTH, CHART_HEIGHT,
featureStatuses,
new String[]{"Covered", "Not Covered"},
new String[]{"green", "gold"},
new String[]{"darkgreen", "GoldenRod"},
CHART_THICKNESS,
2));
content = content.replaceAll("__SCENARIO_DATA__", pieChart.generatePieChart(
CHART_WIDTH, CHART_HEIGHT,
scenarioStatuses,
new String[]{"Covered", "Not Covered"},
new String[]{"green", "gold"},
new String[]{"darkgreen", "GoldenRod"},
CHART_THICKNESS,
2));
return content;
}
@Override
public void execute(boolean toPDF) throws Exception {
// TODO Auto-generated method stub
executeOverviewReport("coverage", toPDF);
}
@Override
public void execute() throws Exception {
executeOverviewReport("coverage");
}
@Override
public CucumberReportTypes getReportType() {
return CucumberReportTypes.COVERAGE_OVERVIEW;
}
@Override
public CucumberReportLink getReportDocLink() {
return CucumberReportLink.COVERAGE_OVERVIEW_URL;
}
}