Skip to content

Commit c8504e2

Browse files
authored
Merge pull request #2668 from Fork-World/2667_result_count
#2667 result count
2 parents 444f463 + a273677 commit c8504e2

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

karate-core/src/main/java/com/intuit/karate/Results.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public class Results {
5050
private final int scenariosFailed;
5151
private final double timeTakenMillis;
5252
private final long endTime;
53-
private final List<String> errors = new ArrayList();
54-
private final List<Map<String, Object>> featureSummary = new ArrayList();
53+
private final List<String> errors = new ArrayList<>();
54+
private final List<Map<String, Object>> featureSummary = new ArrayList<>();
5555

5656
public static Results of(Suite suite) {
5757
return new Results(suite);
@@ -138,7 +138,7 @@ private void printStats() {
138138
}
139139

140140
public Map<String, Object> toKarateJson() {
141-
Map<String, Object> map = new HashMap();
141+
Map<String, Object> map = new HashMap<>();
142142
map.put("version", FileUtils.KARATE_VERSION);
143143
map.put("env", suite.env);
144144
map.put("threads", suite.threadCount);

karate-core/src/main/java/com/intuit/karate/core/FeatureResult.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void printStats() {
7070
}
7171

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

107107
public Map<String, Object> toInfoJson() {
108-
Map<String, Object> map = new HashMap();
108+
Map<String, Object> map = new HashMap<>();
109109
map.put("name", feature.getName());
110110
map.put("description", feature.getDescription());
111111
map.put("prefixedPath", feature.getResource().getPrefixedPath());
@@ -118,7 +118,7 @@ public Map<String, Object> toInfoJson() {
118118
}
119119

120120
public Map<String, Object> toSummaryJson() {
121-
Map<String, Object> map = new HashMap();
121+
Map<String, Object> map = new HashMap<>();
122122
map.put("failed", isFailed());
123123
map.put("name", feature.getName());
124124
map.put("description", feature.getDescription());
@@ -132,7 +132,7 @@ public Map<String, Object> toSummaryJson() {
132132
}
133133

134134
public Map<String, Object> toKarateJson() {
135-
Map<String, Object> map = new HashMap();
135+
Map<String, Object> map = new HashMap<>();
136136
// these first few are only for the ease of reports
137137
// note that they are not involved in the reverse fromKarateJson()
138138
map.put("name", feature.getName());
@@ -148,7 +148,7 @@ public Map<String, Object> toKarateJson() {
148148
}
149149
map.put("resultDate", resultDate);
150150
map.put("prefixedPath", feature.getResource().getPrefixedPath());
151-
List<Map<String, Object>> list = new ArrayList(scenarioResults.size());
151+
List<Map<String, Object>> list = new ArrayList<>(scenarioResults.size());
152152
map.put("scenarioResults", list);
153153
for (ScenarioResult sr : scenarioResults) {
154154
list.add(sr.toKarateJson());
@@ -163,7 +163,7 @@ public Map<String, Object> toKarateJson() {
163163
}
164164

165165
public Map<String, Object> toCucumberJson() {
166-
Map<String, Object> map = new HashMap();
166+
Map<String, Object> map = new HashMap<>();
167167
map.put("keyword", Feature.KEYWORD);
168168
map.put("line", feature.getLine());
169169
map.put("uri", displayName);
@@ -177,7 +177,7 @@ public Map<String, Object> toCucumberJson() {
177177
if (feature.getTags() != null) {
178178
map.put("tags", ScenarioResult.tagsToCucumberJson(feature.getTags()));
179179
}
180-
List<Map<String, Object>> list = new ArrayList(scenarioResults.size());
180+
List<Map<String, Object>> list = new ArrayList<>(scenarioResults.size());
181181
map.put("elements", list);
182182
for (ScenarioResult sr : scenarioResults) {
183183
Map<String, Object> backgroundMap = sr.backgroundToCucumberJson();
@@ -190,7 +190,7 @@ public Map<String, Object> toCucumberJson() {
190190
}
191191

192192
public List<StepResult> getAllScenarioStepResultsNotHidden() {
193-
List<StepResult> list = new ArrayList();
193+
List<StepResult> list = new ArrayList<>();
194194
for (ScenarioResult sr : scenarioResults) {
195195
list.addAll(sr.getStepResultsNotHidden());
196196
}
@@ -286,7 +286,7 @@ public boolean isFailed() {
286286
}
287287

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

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

311311
public void setConfig(Config config) {

karate-core/src/main/java/com/intuit/karate/core/ScenarioResult.java

+7
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ public static ScenarioResult fromKarateJson(File workingDir, Feature feature, Ma
189189
}
190190
scenario.setSteps(steps);
191191
}
192+
193+
if (scenario.getTagsEffective().contains(Tag.FAIL) && sr.isFailed()) {
194+
if (!sr.getErrorMessage().startsWith(ScenarioRuntime.EXPECT_TEST_TO_FAIL_BECAUSE_OF_FAIL_TAG)) {
195+
sr.ignoreFailedStep();
196+
}
197+
198+
}
192199
return sr;
193200
}
194201

karate-core/src/main/java/com/intuit/karate/core/ScenarioRuntime.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.intuit.karate.ScenarioActions;
3131
import com.intuit.karate.StringUtils;
3232
import com.intuit.karate.graal.JsEngine;
33-
import com.intuit.karate.graal.JsValue;
3433
import com.intuit.karate.http.ResourceType;
3534
import com.intuit.karate.shell.StringLogAppender;
3635

@@ -73,14 +72,14 @@ public ScenarioRuntime(FeatureRuntime featureRuntime, Scenario scenario) {
7372
perfMode = featureRuntime.perfHook != null;
7473
if (caller.isNone()) {
7574
logAppender = new StringLogAppender(false);
76-
engine = new ScenarioEngine(caller.getParentConfig(false), this, new HashMap(), logger);
75+
engine = new ScenarioEngine(caller.getParentConfig(false), this, new HashMap<>(), logger);
7776
} else if (caller.isSharedScope()) {
7877
logAppender = caller.parentRuntime.logAppender;
7978
engine = new ScenarioEngine(caller.getParentConfig(false), this, caller.getParentVars(false), logger);
8079
} else { // new, but clone and copy data
8180
logAppender = caller.parentRuntime.logAppender;
8281
// in this case, parent variables are set via magic variables - see initMagicVariables()
83-
engine = new ScenarioEngine(caller.getParentConfig(true), this, new HashMap(), logger);
82+
engine = new ScenarioEngine(caller.getParentConfig(true), this, new HashMap<>(), logger);
8483
}
8584
logger.setAppender(logAppender);
8685
actions = new ScenarioActions(engine);
@@ -97,7 +96,7 @@ public ScenarioRuntime(FeatureRuntime featureRuntime, Scenario scenario) {
9796
if (featureRuntime.setupResult != null) {
9897
// TODO improve this and simplify report rendering code in report/karate-feature.html
9998
StepResult sr = result.addFakeStepResult("@setup", null);
100-
List<FeatureResult> list = new ArrayList(1);
99+
List<FeatureResult> list = new ArrayList<>(1);
101100
FeatureResult fr = new FeatureResult(featureRuntime.featureCall.feature);
102101
fr.setCallDepth(1);
103102
fr.addResult(featureRuntime.setupResult);
@@ -116,7 +115,7 @@ private Map<String, Object> initMagicVariables() {
116115
// and not "visible" and tracked in ScenarioEngine.vars
117116
// one consequence is that they won't show up in the debug variables view
118117
// but more importantly don't get passed back to caller and float around, bloating memory
119-
Map<String, Object> map = new HashMap();
118+
Map<String, Object> map = new HashMap<>();
120119
if (!caller.isNone()) {
121120
// karate principle: parent variables are always "visible"
122121
// so we inject the parent variables
@@ -172,7 +171,7 @@ private Embed saveToFileAndCreateEmbed(byte[] bytes, ResourceType resourceType)
172171

173172
public Embed embed(byte[] bytes, ResourceType resourceType) {
174173
if (embeds == null) {
175-
embeds = new ArrayList();
174+
embeds = new ArrayList<>();
176175
}
177176
Embed embed = saveToFileAndCreateEmbed(bytes, resourceType);
178177
embeds.add(embed);
@@ -190,7 +189,7 @@ public Embed embedVideo(File file) {
190189

191190
public void addCallResult(FeatureResult fr) {
192191
if (callResults == null) {
193-
callResults = new ArrayList();
192+
callResults = new ArrayList<>();
194193
}
195194
callResults.add(fr);
196195
}
@@ -269,7 +268,7 @@ public boolean hotReload() {
269268
}
270269

271270
public Map<String, Object> getScenarioInfo() {
272-
Map<String, Object> info = new HashMap(5);
271+
Map<String, Object> info = new HashMap<>(5);
273272
File featureFile = featureRuntime.featureCall.feature.getResource().getFile();
274273
if (featureFile != null) {
275274
info.put("featureDir", featureFile.getParent());

karate-core/src/test/java/com/intuit/karate/core/runner/RunnerTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ void testRunningFeatureFromJavaApi() {
7474
assertEquals("normal", result.get("configSource"));
7575
}
7676

77+
@Test
78+
void testRunningFeatureWithFailAnnotationFromJavaApi() {
79+
Results results = Runner.path("classpath:com/intuit/karate/core/fail-tag.feature").parallel(1);
80+
assertEquals(0, results.getFailCount());
81+
}
82+
83+
@Test
84+
void testRunningFeatureWithFailAnnotationFailureFromJavaApi() {
85+
Results results = Runner.path("classpath:com/intuit/karate/core/fail-tag-failure.feature").parallel(1);
86+
assertEquals(1, results.getFailCount());
87+
}
88+
7789
@Test
7890
void testRunningFeatureFailureFromJavaApi() {
7991
try {

0 commit comments

Comments
 (0)