Skip to content

Commit

Permalink
Allow undefined and pending steps to not fail
Browse files Browse the repository at this point in the history
Issue #692
  • Loading branch information
damianszczepanik committed Aug 5, 2019
1 parent 252f9f4 commit fdf587b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![License](https://img.shields.io/badge/license-GNU%20LGPL%20v2.1-blue.svg)](https://raw.githubusercontent.com/damianszczepanik/cucumber-reporting/master/LICENCE)
[![Contributors](https://img.shields.io/github/contributors/damianszczepanik/cucumber-reporting.svg)](https://github.com/damianszczepanik/cucumber-reporting/graphs/contributors)

# Publish pretty [cucumber](http://cukes.info/) reports
# Publish pretty [cucumber](https://cucumber.io/) reports

This is a Java report publisher primarily created to publish cucumber reports on the Jenkins build server.
It publishes pretty html reports with charts showing the results of cucumber runs. It has been split out into a standalone package so it can be used for Jenkins and maven command line as well as any other packaging that might be useful. Generated report has no dependency so can be viewed offline.
Expand Down Expand Up @@ -51,6 +51,8 @@ String projectName = "cucumberProject";
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
// optional configuration - check javadoc for details
configuration.addPresentationModes(PresentationMode.RUN_WITH_JENKINS);
// do not make scenario failed when step has status SKIPPED
configuration.setNotFailingStatuses(Collections.singleton(Status.SKIPPED));
configuration.setBuildNumber(buildNumber);
// addidtional metadata presented on main page
configuration.addClassifications("Platform", "Windows");
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/net/masterthought/cucumber/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.apache.commons.collections.CollectionUtils;

import net.masterthought.cucumber.json.support.Status;
import net.masterthought.cucumber.presentation.PresentationMode;
import net.masterthought.cucumber.reducers.ReducingMethod;
import net.masterthought.cucumber.sorting.SortingMethod;
Expand All @@ -33,6 +38,8 @@ public class Configuration {
private List<PresentationMode> presentationModes = new ArrayList<>();
private List<String> classificationFiles;

private Set<Status> notFailingStatuses = Collections.emptySet();

public Configuration(File reportDirectory, String projectName) {
this.reportDirectory = reportDirectory;
this.projectName = projectName;
Expand Down Expand Up @@ -283,4 +290,21 @@ public void addClassificationFiles(List<String> classificationFiles) {
public List<String> getClassificationFiles() {
return this.classificationFiles;
}

/**
* Gets statuses which do not fail scenario.
*/
public Set<Status> getNotFailingStatuses() {
return notFailingStatuses;
}

/**
* Sets {@link net.masterthought.cucumber.json.support.Status statuses}
* of {@link net.masterthought.cucumber.json.Step steps} which should not fail the scenario.
*/
public void setNotFailingStatuses(Set<Status> notFailingStatuses) {
if (CollectionUtils.isNotEmpty(notFailingStatuses)) {
this.notFailingStatuses = notFailingStatuses;
}
}
}
5 changes: 3 additions & 2 deletions src/main/java/net/masterthought/cucumber/json/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.commons.lang.StringUtils;

import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.json.support.Durationable;
import net.masterthought.cucumber.json.support.Status;
import net.masterthought.cucumber.json.support.StatusCounter;
Expand Down Expand Up @@ -96,7 +97,7 @@ public String getFormattedDuration() {
return Util.formatDuration(duration);
}

public void setMetaData(Feature feature) {
public void setMetaData(Feature feature, Configuration configuration) {
this.feature = feature;

for (Step step : steps) {
Expand All @@ -105,7 +106,7 @@ public void setMetaData(Feature feature) {

beforeStatus = new StatusCounter(before).getFinalStatus();
afterStatus = new StatusCounter(after).getFinalStatus();
stepsStatus = new StatusCounter(steps).getFinalStatus();
stepsStatus = new StatusCounter(steps, configuration.getNotFailingStatuses()).getFinalStatus();
elementStatus = calculateElementStatus();

calculateDuration();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/masterthought/cucumber/json/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public int getFailedScenarios() {
*/
public void setMetaData(int jsonFileNo, Configuration configuration) {
for (Element element : elements) {
element.setMetaData(this);
element.setMetaData(this, configuration);

if (element.isScenario()) {
scenarios.add(element);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.masterthought.cucumber.json.support;

import java.util.Collections;
import java.util.EnumMap;
import java.util.Set;

/**
* Keeps information about statuses occurrence.
Expand All @@ -20,16 +22,25 @@ public class StatusCounter {

private int size = 0;

public StatusCounter() {
for (Status status : Status.values()) {
counter.put(status, 0);
}
public StatusCounter(Resultsable[] resultsables) {
this(resultsables, Collections.emptySet());
}

public StatusCounter(Resultsable[] resultsables) {
public StatusCounter(Resultsable[] resultsables, Set<Status> notFailingStatuses) {
this();
for (Resultsable resultsable : resultsables) {
incrementFor(resultsable.getResult().getStatus());
Status status = resultsable.getResult().getStatus();
if (notFailingStatuses.contains(status)) {
incrementFor(Status.PASSED);
} else {
incrementFor(status);
}
}
}

public StatusCounter() {
for (Status status : Status.values()) {
counter.put(status, 0);
}
}

Expand Down

0 comments on commit fdf587b

Please sign in to comment.