Skip to content
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

#2667 result count #2668

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions karate-core/src/main/java/com/intuit/karate/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class Results {
private final int scenariosFailed;
private final double timeTakenMillis;
private final long endTime;
private final List<String> errors = new ArrayList();
private final List<Map<String, Object>> featureSummary = new ArrayList();
private final List<String> errors = new ArrayList<>();
private final List<Map<String, Object>> featureSummary = new ArrayList<>();

public static Results of(Suite suite) {
return new Results(suite);
Expand Down Expand Up @@ -138,7 +138,7 @@ private void printStats() {
}

public Map<String, Object> toKarateJson() {
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<>();
map.put("version", FileUtils.KARATE_VERSION);
map.put("env", suite.env);
map.put("threads", suite.threadCount);
Expand Down
20 changes: 10 additions & 10 deletions karate-core/src/main/java/com/intuit/karate/core/FeatureResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void printStats() {
}

public List<File> getAllEmbedFiles() {
List<File> files = new ArrayList();
List<File> files = new ArrayList<>();
for (ScenarioResult sr : scenarioResults) {
for (StepResult stepResult : sr.getStepResults()) {
if (stepResult.getEmbeds() != null) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public static FeatureResult fromKarateJson(File workingDir, Map<String, Object>
}

public Map<String, Object> toInfoJson() {
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<>();
map.put("name", feature.getName());
map.put("description", feature.getDescription());
map.put("prefixedPath", feature.getResource().getPrefixedPath());
Expand All @@ -118,7 +118,7 @@ public Map<String, Object> toInfoJson() {
}

public Map<String, Object> toSummaryJson() {
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<>();
map.put("failed", isFailed());
map.put("name", feature.getName());
map.put("description", feature.getDescription());
Expand All @@ -132,7 +132,7 @@ public Map<String, Object> toSummaryJson() {
}

public Map<String, Object> toKarateJson() {
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<>();
// these first few are only for the ease of reports
// note that they are not involved in the reverse fromKarateJson()
map.put("name", feature.getName());
Expand All @@ -148,7 +148,7 @@ public Map<String, Object> toKarateJson() {
}
map.put("resultDate", resultDate);
map.put("prefixedPath", feature.getResource().getPrefixedPath());
List<Map<String, Object>> list = new ArrayList(scenarioResults.size());
List<Map<String, Object>> list = new ArrayList<>(scenarioResults.size());
map.put("scenarioResults", list);
for (ScenarioResult sr : scenarioResults) {
list.add(sr.toKarateJson());
Expand All @@ -163,7 +163,7 @@ public Map<String, Object> toKarateJson() {
}

public Map<String, Object> toCucumberJson() {
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<>();
map.put("keyword", Feature.KEYWORD);
map.put("line", feature.getLine());
map.put("uri", displayName);
Expand All @@ -177,7 +177,7 @@ public Map<String, Object> toCucumberJson() {
if (feature.getTags() != null) {
map.put("tags", ScenarioResult.tagsToCucumberJson(feature.getTags()));
}
List<Map<String, Object>> list = new ArrayList(scenarioResults.size());
List<Map<String, Object>> list = new ArrayList<>(scenarioResults.size());
map.put("elements", list);
for (ScenarioResult sr : scenarioResults) {
Map<String, Object> backgroundMap = sr.backgroundToCucumberJson();
Expand All @@ -190,7 +190,7 @@ public Map<String, Object> toCucumberJson() {
}

public List<StepResult> getAllScenarioStepResultsNotHidden() {
List<StepResult> list = new ArrayList();
List<StepResult> list = new ArrayList<>();
for (ScenarioResult sr : scenarioResults) {
list.addAll(sr.getStepResultsNotHidden());
}
Expand Down Expand Up @@ -286,7 +286,7 @@ public boolean isFailed() {
}

public List<String> getErrors() {
List<String> errors = new ArrayList();
List<String> errors = new ArrayList<>();
for (ScenarioResult sr : scenarioResults) {
if (sr.isFailed()) {
errors.add(sr.getErrorMessage());
Expand All @@ -305,7 +305,7 @@ public void setVariables(Map<String, Object> resultVariables) {

public Map<String, Object> getVariables() {
// edge case if no scenarios were run
return resultVariables == null ? new HashMap() : resultVariables;
return resultVariables == null ? new HashMap<>() : resultVariables;
}

public void setConfig(Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ public static ScenarioResult fromKarateJson(File workingDir, Feature feature, Ma
}
scenario.setSteps(steps);
}

if (scenario.getTagsEffective().contains(Tag.FAIL) && sr.isFailed()) {
if (!sr.getErrorMessage().startsWith(ScenarioRuntime.EXPECT_TEST_TO_FAIL_BECAUSE_OF_FAIL_TAG)) {
sr.ignoreFailedStep();
}

}
return sr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.intuit.karate.ScenarioActions;
import com.intuit.karate.StringUtils;
import com.intuit.karate.graal.JsEngine;
import com.intuit.karate.graal.JsValue;
import com.intuit.karate.http.ResourceType;
import com.intuit.karate.shell.StringLogAppender;

Expand Down Expand Up @@ -73,14 +72,14 @@ public ScenarioRuntime(FeatureRuntime featureRuntime, Scenario scenario) {
perfMode = featureRuntime.perfHook != null;
if (caller.isNone()) {
logAppender = new StringLogAppender(false);
engine = new ScenarioEngine(caller.getParentConfig(false), this, new HashMap(), logger);
engine = new ScenarioEngine(caller.getParentConfig(false), this, new HashMap<>(), logger);
} else if (caller.isSharedScope()) {
logAppender = caller.parentRuntime.logAppender;
engine = new ScenarioEngine(caller.getParentConfig(false), this, caller.getParentVars(false), logger);
} else { // new, but clone and copy data
logAppender = caller.parentRuntime.logAppender;
// in this case, parent variables are set via magic variables - see initMagicVariables()
engine = new ScenarioEngine(caller.getParentConfig(true), this, new HashMap(), logger);
engine = new ScenarioEngine(caller.getParentConfig(true), this, new HashMap<>(), logger);
}
logger.setAppender(logAppender);
actions = new ScenarioActions(engine);
Expand All @@ -97,7 +96,7 @@ public ScenarioRuntime(FeatureRuntime featureRuntime, Scenario scenario) {
if (featureRuntime.setupResult != null) {
// TODO improve this and simplify report rendering code in report/karate-feature.html
StepResult sr = result.addFakeStepResult("@setup", null);
List<FeatureResult> list = new ArrayList(1);
List<FeatureResult> list = new ArrayList<>(1);
FeatureResult fr = new FeatureResult(featureRuntime.featureCall.feature);
fr.setCallDepth(1);
fr.addResult(featureRuntime.setupResult);
Expand All @@ -116,7 +115,7 @@ private Map<String, Object> initMagicVariables() {
// and not "visible" and tracked in ScenarioEngine.vars
// one consequence is that they won't show up in the debug variables view
// but more importantly don't get passed back to caller and float around, bloating memory
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<>();
if (!caller.isNone()) {
// karate principle: parent variables are always "visible"
// so we inject the parent variables
Expand Down Expand Up @@ -172,7 +171,7 @@ private Embed saveToFileAndCreateEmbed(byte[] bytes, ResourceType resourceType)

public Embed embed(byte[] bytes, ResourceType resourceType) {
if (embeds == null) {
embeds = new ArrayList();
embeds = new ArrayList<>();
}
Embed embed = saveToFileAndCreateEmbed(bytes, resourceType);
embeds.add(embed);
Expand All @@ -190,7 +189,7 @@ public Embed embedVideo(File file) {

public void addCallResult(FeatureResult fr) {
if (callResults == null) {
callResults = new ArrayList();
callResults = new ArrayList<>();
}
callResults.add(fr);
}
Expand Down Expand Up @@ -269,7 +268,7 @@ public boolean hotReload() {
}

public Map<String, Object> getScenarioInfo() {
Map<String, Object> info = new HashMap(5);
Map<String, Object> info = new HashMap<>(5);
File featureFile = featureRuntime.featureCall.feature.getResource().getFile();
if (featureFile != null) {
info.put("featureDir", featureFile.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ void testRunningFeatureFromJavaApi() {
assertEquals("normal", result.get("configSource"));
}

@Test
void testRunningFeatureWithFailAnnotationFromJavaApi() {
Results results = Runner.path("classpath:com/intuit/karate/core/fail-tag.feature").parallel(1);
assertEquals(0, results.getFailCount());
}

@Test
void testRunningFeatureWithFailAnnotationFailureFromJavaApi() {
Results results = Runner.path("classpath:com/intuit/karate/core/fail-tag-failure.feature").parallel(1);
assertEquals(1, results.getFailCount());
}

@Test
void testRunningFeatureFailureFromJavaApi() {
try {
Expand Down