All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.github.mkolisnyk.cucumber.reporting.CucumberCoverageOverview Maven / Gradle / Ivy
package com.github.mkolisnyk.cucumber.reporting;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import com.github.mkolisnyk.cucumber.reporting.types.result.CucumberFeatureResult;
import com.github.mkolisnyk.cucumber.reporting.types.result.CucumberScenarioResult;
public class CucumberCoverageOverview extends CucumberResultsOverview {
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;
}
}
@Override
protected String getFeatureData(CucumberFeatureResult[] results) {
int passed = 0;
int undefined = 0;
for (CucumberFeatureResult result : results) {
if (result.getStatus().equals("undefined") || result.getUndefined() > 0) {
undefined++;
} else {
passed++;
}
}
return String.format("['Covered', %d], ['Not Covered', %d]", passed, undefined);
}
@Override
protected String getScenarioData(CucumberFeatureResult[] results) {
int passed = 0;
int undefined = 0;
for (CucumberFeatureResult result : results) {
result.setIncludeCoverageTags(includeCoverageTags);
result.setExcludeCoverageTags(excludeCoverageTags);
for (CucumberScenarioResult element : result.getElements()) {
element.setIncludeCoverageTags(includeCoverageTags);
element.setExcludeCoverageTags(excludeCoverageTags);
//if (element.getStatus().trim().equalsIgnoreCase("undefined")) {
if (element.getStatus().equals("undefined") || element.getUndefined() > 0) {
undefined++;
} else {
passed++;
}
}
}
return String.format("['Covered', %d], ['Not Covered', %d]", passed, undefined);
}
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";
}
}
@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(
"%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 ";
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(
""
+ "%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);
content = content.replaceAll("__FEATURE_DATA__", getFeatureData(results));
content = content.replaceAll("__SCENARIO_DATA__", getScenarioData(results));
return content;
}
public void executeCoverageReport() throws Exception {
executeOverviewReport("coverage");
}
}