|
6 | 6 |
|
7 | 7 | import java.util.AbstractMap.SimpleEntry;
|
8 | 8 | import java.util.ArrayList;
|
| 9 | +import java.util.Arrays; |
9 | 10 | import java.util.Collections;
|
10 | 11 | import java.util.HashMap;
|
11 | 12 | import java.util.List;
|
|
15 | 16 |
|
16 | 17 | public class RerunFormatterTest {
|
17 | 18 |
|
| 19 | + @Test |
| 20 | + public void should_leave_report_empty_when_no_scenario_fails() throws Throwable { |
| 21 | + CucumberFeature feature = TestHelper.feature("path/test.feature", "" + |
| 22 | + "Feature: feature name\n" + |
| 23 | + " Scenario: scenario name\n" + |
| 24 | + " Given first step\n" + |
| 25 | + " When second step\n" + |
| 26 | + " Then third step\n"); |
| 27 | + Map<String, String> stepsToResult = new HashMap<String, String>(); |
| 28 | + stepsToResult.put("first step", "passed"); |
| 29 | + stepsToResult.put("second step", "passed"); |
| 30 | + stepsToResult.put("third step", "passed"); |
| 31 | + |
| 32 | + String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult); |
| 33 | + |
| 34 | + assertEquals("", formatterOutput); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void should_use_scenario_location_when_scenario_step_fails() throws Throwable { |
| 39 | + CucumberFeature feature = TestHelper.feature("path/test.feature", "" + |
| 40 | + "Feature: feature name\n" + |
| 41 | + " Scenario: scenario name\n" + |
| 42 | + " Given first step\n" + |
| 43 | + " When second step\n" + |
| 44 | + " Then third step\n"); |
| 45 | + Map<String, String> stepsToResult = new HashMap<String, String>(); |
| 46 | + stepsToResult.put("first step", "passed"); |
| 47 | + stepsToResult.put("second step", "passed"); |
| 48 | + stepsToResult.put("third step", "failed"); |
| 49 | + |
| 50 | + String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult); |
| 51 | + |
| 52 | + assertEquals("path/test.feature:2", formatterOutput); |
| 53 | + } |
| 54 | + |
18 | 55 | @Test
|
19 | 56 | public void should_use_scenario_location_when_background_step_fails() throws Throwable {
|
20 | 57 | CucumberFeature feature = TestHelper.feature("path/test.feature", "" +
|
@@ -95,17 +132,71 @@ public void should_use_scenario_location_when_after_hook_fails() throws Throwabl
|
95 | 132 | assertEquals("path/test.feature:2", formatterOutput);
|
96 | 133 | }
|
97 | 134 |
|
| 135 | + @Test |
| 136 | + public void should_one_entry_for_feature_with_many_failing_scenarios() throws Throwable { |
| 137 | + CucumberFeature feature = TestHelper.feature("path/test.feature", "" + |
| 138 | + "Feature: feature name\n" + |
| 139 | + " Scenario: scenario 1 name\n" + |
| 140 | + " When first step\n" + |
| 141 | + " Then second step\n" + |
| 142 | + " Scenario: scenario 2 name\n" + |
| 143 | + " When third step\n" + |
| 144 | + " Then forth step\n"); |
| 145 | + Map<String, String> stepsToResult = new HashMap<String, String>(); |
| 146 | + stepsToResult.put("first step", "passed"); |
| 147 | + stepsToResult.put("second step", "failed"); |
| 148 | + stepsToResult.put("third step", "failed"); |
| 149 | + stepsToResult.put("forth step", "passed"); |
| 150 | + |
| 151 | + String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult); |
| 152 | + |
| 153 | + assertEquals("path/test.feature:2:5", formatterOutput); |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + public void should_one_entry_for_each_failing_feature() throws Throwable { |
| 158 | + CucumberFeature feature1 = TestHelper.feature("path/first.feature", "" + |
| 159 | + "Feature: feature 1 name\n" + |
| 160 | + " Scenario: scenario 1 name\n" + |
| 161 | + " When first step\n" + |
| 162 | + " Then second step\n"); |
| 163 | + CucumberFeature feature2 = TestHelper.feature("path/second.feature", "" + |
| 164 | + "Feature: feature 2 name\n" + |
| 165 | + " Scenario: scenario 2 name\n" + |
| 166 | + " When third step\n" + |
| 167 | + " Then forth step\n"); |
| 168 | + Map<String, String> stepsToResult = new HashMap<String, String>(); |
| 169 | + stepsToResult.put("first step", "passed"); |
| 170 | + stepsToResult.put("second step", "failed"); |
| 171 | + stepsToResult.put("third step", "failed"); |
| 172 | + stepsToResult.put("forth step", "passed"); |
| 173 | + |
| 174 | + String formatterOutput = runFeaturesWithRerunFormatter(Arrays.asList(feature1, feature2), stepsToResult); |
| 175 | + |
| 176 | + assertEquals("path/second.feature:2 path/first.feature:2", formatterOutput); |
| 177 | + } |
| 178 | + |
98 | 179 | private String runFeatureWithRerunFormatter(final CucumberFeature feature, final Map<String, String> stepsToResult)
|
99 | 180 | throws Throwable {
|
100 | 181 | return runFeatureWithRerunFormatter(feature, stepsToResult, Collections.<SimpleEntry<String, String>>emptyList());
|
101 | 182 | }
|
102 | 183 |
|
103 | 184 | private String runFeatureWithRerunFormatter(final CucumberFeature feature, final Map<String, String> stepsToResult,
|
104 | 185 | final List<SimpleEntry<String, String>> hooks) throws Throwable {
|
| 186 | + return runFeaturesWithRerunFormatter(Arrays.asList(feature), stepsToResult, hooks); |
| 187 | + } |
| 188 | + |
| 189 | + private String runFeaturesWithRerunFormatter(final List<CucumberFeature> features, final Map<String, String> stepsToResult) |
| 190 | + throws Throwable { |
| 191 | + return runFeaturesWithRerunFormatter(features, stepsToResult, Collections.<SimpleEntry<String, String>>emptyList()); |
| 192 | + } |
| 193 | + |
| 194 | + private String runFeaturesWithRerunFormatter(final List<CucumberFeature> features, final Map<String, String> stepsToResult, |
| 195 | + final List<SimpleEntry<String, String>> hooks) throws Throwable { |
105 | 196 | final StringBuffer buffer = new StringBuffer();
|
106 | 197 | final RerunFormatter rerunFormatter = new RerunFormatter(buffer);
|
107 | 198 | final long stepHookDuration = 0;
|
108 |
| - TestHelper.runFeatureWithFormatter(feature, stepsToResult, hooks, stepHookDuration, rerunFormatter, rerunFormatter); |
| 199 | + TestHelper.runFeaturesWithFormatter(features, stepsToResult, hooks, stepHookDuration, rerunFormatter, rerunFormatter); |
109 | 200 | return buffer.toString();
|
110 | 201 | }
|
111 | 202 |
|
|
0 commit comments