Permalink
Browse files

Attempt to make JUnit report more correctly for Scenario Outlines.

  • Loading branch information...
1 parent e572769 commit 7aa84bdb4a3787131fc7724044c8aad783b40256 @aslakhellesoy aslakhellesoy committed Jul 14, 2012
@@ -7,6 +7,8 @@
import gherkin.formatter.model.DocString;
import gherkin.formatter.model.Examples;
import gherkin.formatter.model.ExamplesTableRow;
+import gherkin.formatter.model.Match;
+import gherkin.formatter.model.Result;
import gherkin.formatter.model.Row;
import gherkin.formatter.model.Scenario;
import gherkin.formatter.model.ScenarioOutline;
@@ -38,6 +40,7 @@ public void examples(Examples examples) {
@Override
public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
format(formatter);
+ reportOutlineSteps(formatter, reporter);
for (CucumberExamples cucumberExamples : cucumberExamplesList) {
cucumberExamples.format(formatter);
List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
@@ -47,6 +50,14 @@ public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
}
}
+ private void reportOutlineSteps(Formatter formatter, Reporter reporter) {
+ for (Step step : getSteps()) {
+// formatter.step(step);
+ reporter.match(Match.UNDEFINED);
+ reporter.result(Result.SKIPPED);
+ }
+ }
+
CucumberScenario createExampleScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> examplesTags) {
Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, tagStatement.getKeyword(), tagStatement.getName(), "", example.getLine(), example.getId());
CucumberScenario cucumberScenario = new CucumberScenario(cucumberFeature, cucumberBackground, exampleScenario, example);
@@ -10,7 +10,7 @@
class ExampleStep extends Step {
// TODO: Use this to colour columns in associated Example row with our associated status.
- private final Set<Integer> matchedColumns;
+ private final transient Set<Integer> matchedColumns;
public ExampleStep(List<Comment> comments, String keyword, String name, int line, List<DataTableRow> rows, DocString docString, Set<Integer> matchedColumns) {
super(comments, keyword, name, line, rows, docString);
@@ -19,6 +19,17 @@
private static final List<Comment> NO_COMMENTS = Collections.emptyList();
@Test
+ public void escapesDollars() {
+ String expected = "" +
+ "@Given(\"^I have (\\\\d+) cukes in my \\\"([^\\\"]*)\\\" belly$\")\n" +
+ "public void I_have_cukes_in_my_belly(int arg1, String arg2) throws Throwable {\n" +
+ " // Express the Regexp above with the code you wish you had\n" +
+ " throw new PendingException();\n" +
+ "}\n";
+ assertEquals(expected, snippetFor("I have $2 in my account"));
+ }
+
+ @Test
public void generatesPlainSnippet() {
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes in my \\\"([^\\\"]*)\\\" belly$\")\n" +
@@ -18,11 +18,11 @@
* Runs a scenario, or a "synthetic" scenario derived from an Examples row.
*/
class ExecutionUnitRunner extends ParentRunner<Step> {
+ private final Map<Step, Description> stepDescriptions = new HashMap<Step, Description>();
private final Runtime runtime;
private final CucumberScenario cucumberScenario;
private final JUnitReporter jUnitReporter;
private Description description;
- private final Map<Step, Description> stepDescriptions = new HashMap<Step, Description>();
public ExecutionUnitRunner(Runtime runtime, CucumberScenario cucumberScenario, JUnitReporter jUnitReporter) throws InitializationError {
super(ExecutionUnitRunner.class);
@@ -53,11 +53,15 @@ public void finishExecutionUnit() {
} else {
executionUnitNotifier.fireTestFinished();
}
+ executionUnitNotifier = null;
}
public void match(Match match) {
- Description description = executionUnitRunner.describeChild(steps.remove(0));
- stepNotifier = new EachTestNotifier(runNotifier, description);
+ if(executionUnitRunner != null) {
+ // It's null when a scenario outline step is "matched"
+ Description description = executionUnitRunner.describeChild(steps.remove(0));
+ stepNotifier = new EachTestNotifier(runNotifier, description);
+ }
reporter.match(match);
}
@@ -72,30 +76,33 @@ public void write(String text) {
}
public void result(Result result) {
- Throwable error = result.getError();
- if (Result.SKIPPED == result) {
- stepNotifier.fireTestIgnored();
- } else if (isPendingOrUndefined(result)) {
- addFailureOrIgnoreStep(result);
- } else {
- if (stepNotifier != null) {
- //Should only fireTestStarted if not ignored
- stepNotifier.fireTestStarted();
+ if(stepNotifier != null) {
+ // It's null if this is the "result" of a scenario outline step
+ Throwable error = result.getError();
+ if (Result.SKIPPED == result) {
+ stepNotifier.fireTestIgnored();
+ } else if (isPendingOrUndefined(result)) {
+ addFailureOrIgnoreStep(result);
+ } else {
+ if (stepNotifier != null) {
+ //Should only fireTestStarted if not ignored
+ stepNotifier.fireTestStarted();
+ if (error != null) {
+ stepNotifier.addFailure(error);
+ }
+ stepNotifier.fireTestFinished();
+ }
if (error != null) {
- stepNotifier.addFailure(error);
+ executionUnitNotifier.addFailure(error);
}
- stepNotifier.fireTestFinished();
}
- if (error != null) {
- executionUnitNotifier.addFailure(error);
+ if (steps.isEmpty()) {
+ // We have run all of our steps. Set the stepNotifier to null so that
+ // if an error occurs in an After block, it's reported against the scenario
+ // instead (via executionUnitNotifier).
+ stepNotifier = null;
}
}
- if (steps.isEmpty()) {
- // We have run all of our steps. Set the stepNotifier to null so that
- // if an error occurs in an After block, it's reported against the scenario
- // instead (via executionUnitNotifier).
- stepNotifier = null;
- }
reporter.result(result);
}
@@ -5,6 +5,7 @@
import cucumber.runtime.model.CucumberScenarioOutline;
import org.junit.runner.Description;
import org.junit.runner.Runner;
+import org.junit.runner.notification.RunNotifier;
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;
@@ -13,18 +14,31 @@
import static cucumber.junit.DescriptionFactory.createDescription;
class ScenarioOutlineRunner extends Suite {
+ private final Runtime runtime;
private final CucumberScenarioOutline cucumberScenarioOutline;
+ private final JUnitReporter jUnitReporter;
private Description description;
public ScenarioOutlineRunner(Runtime runtime, CucumberScenarioOutline cucumberScenarioOutline, JUnitReporter jUnitReporter) throws InitializationError {
super(null, new ArrayList<Runner>());
+ this.runtime = runtime;
this.cucumberScenarioOutline = cucumberScenarioOutline;
+ this.jUnitReporter = jUnitReporter;
for (CucumberExamples cucumberExamples : cucumberScenarioOutline.getCucumberExamplesList()) {
getChildren().add(new ExamplesRunner(runtime, cucumberExamples, jUnitReporter));
}
}
@Override
+ public void run(RunNotifier notifier) {
+ super.run(notifier);
+// jUnitReporter.startExecutionUnit(this, notifier);
+ // This causes runChild to never be called, which seems OK.
+ cucumberScenarioOutline.run(jUnitReporter, jUnitReporter, runtime);
+// jUnitReporter.finishExecutionUnit();
+ }
+
+ @Override
public String getName() {
return cucumberScenarioOutline.getVisualName();
}
@@ -5,5 +5,6 @@
@RunWith(Cucumber.class)
//@Cucumber.Options(features = "classpath:cucumber/runtime/java/picocontainer/dates.feature:3:11")
+@Cucumber.Options(tags="@gh210", format = "json-pretty")
public class RunCukesTest {
}

0 comments on commit 7aa84bd

Please sign in to comment.