diff --git a/core/src/main/java/cucumber/runner/Runner.java b/core/src/main/java/cucumber/runner/Runner.java index cfe75879fa..af3c47e49f 100644 --- a/core/src/main/java/cucumber/runner/Runner.java +++ b/core/src/main/java/cucumber/runner/Runner.java @@ -92,12 +92,14 @@ public void reportStepDefinitions(StepDefinitionReporter stepDefinitionReporter) private TestCase createTestCaseForPickle(PickleEvent pickleEvent) { List testSteps = new ArrayList(); - if (!runtimeOptions.isDryRun()) { - addTestStepsForBeforeHooks(testSteps, pickleEvent.pickle.getTags()); - } - addTestStepsForPickleSteps(testSteps, pickleEvent); - if (!runtimeOptions.isDryRun()) { - addTestStepsForAfterHooks(testSteps, pickleEvent.pickle.getTags()); + if (!pickleEvent.pickle.getSteps().isEmpty()) { + if (!runtimeOptions.isDryRun()) { + addTestStepsForBeforeHooks(testSteps, pickleEvent.pickle.getTags()); + } + addTestStepsForPickleSteps(testSteps, pickleEvent); + if (!runtimeOptions.isDryRun()) { + addTestStepsForAfterHooks(testSteps, pickleEvent.pickle.getTags()); + } } return new TestCase(testSteps, pickleEvent, runtimeOptions.isDryRun()); } diff --git a/core/src/main/java/cucumber/runtime/ScenarioImpl.java b/core/src/main/java/cucumber/runtime/ScenarioImpl.java index 6b76bf58df..82ac2f5807 100644 --- a/core/src/main/java/cucumber/runtime/ScenarioImpl.java +++ b/core/src/main/java/cucumber/runtime/ScenarioImpl.java @@ -60,6 +60,9 @@ public Collection getSourceTagNames() { @Override public Result.Type getStatus() { + if (stepResults.isEmpty()) { + return Result.Type.UNDEFINED; + } int pos = 0; for (Result stepResult : stepResults) { pos = Math.max(pos, SEVERITY.indexOf(stepResult.getStatus())); diff --git a/core/src/test/java/cucumber/runner/RunnerTest.java b/core/src/test/java/cucumber/runner/RunnerTest.java index 8bd36d57d3..3857d75e30 100644 --- a/core/src/test/java/cucumber/runner/RunnerTest.java +++ b/core/src/test/java/cucumber/runner/RunnerTest.java @@ -40,13 +40,14 @@ public class RunnerTest { private final Backend backend = mock(Backend.class); private final Runtime runtime = createRuntime(backend); private final Runner runner = runtime.getRunner(); - + @Test public void hooks_execute_when_world_exist() throws Throwable { + PickleStep step = mock(PickleStep.class); HookDefinition beforeHook = addBeforeHook(runtime); HookDefinition afterHook = addAfterHook(runtime); - runner.runPickle(createEmptyPickleEvent()); + runner.runPickle(createPickleEventWithSteps(asList(step))); InOrder inOrder = inOrder(beforeHook, afterHook, backend); inOrder.verify(backend).buildWorld(); @@ -70,19 +71,20 @@ public void steps_are_skipped_after_failure() throws Throwable { @Test public void hooks_execute_also_after_failure() throws Throwable { + PickleStep step = mock(PickleStep.class); HookDefinition failingBeforeHook = addBeforeHook(runtime); doThrow(RuntimeException.class).when(failingBeforeHook).execute(Matchers.any()); HookDefinition beforeHook = addBeforeHook(runtime); HookDefinition afterHook = addAfterHook(runtime); - runner.runPickle(createEmptyPickleEvent()); + runner.runPickle(createPickleEventWithSteps(asList(step))); InOrder inOrder = inOrder(failingBeforeHook, beforeHook, afterHook); inOrder.verify(failingBeforeHook).execute(Matchers.any()); inOrder.verify(beforeHook).execute(Matchers.any()); inOrder.verify(afterHook).execute(Matchers.any()); } - + @Test public void steps_are_executed() throws Throwable { final StepDefinition stepDefinition = mock(StepDefinition.class); @@ -96,12 +98,24 @@ public void steps_are_not_executed_on_dry_run() throws Throwable { final Runtime dryRuntime = createRuntime(backend, "--dry-run"); dryRuntime.getRunner().runPickle(createPickleEventMatchingStepDefinitions(asList(stepDefinition), dryRuntime)); verify(stepDefinition, never()).execute(Matchers.anyString(), Matchers.any()); - } - + } + @Test public void hooks_not_executed_in_dry_run_mode() throws Throwable { Runtime runtime = createRuntime(backend, "--dry-run"); Runner runner = runtime.getRunner(); + PickleStep step = mock(PickleStep.class); + HookDefinition beforeHook = addBeforeHook(runtime); + HookDefinition afterHook = addAfterHook(runtime); + + runner.runPickle(createPickleEventWithSteps(asList(step))); + + verify(beforeHook, never()).execute(Matchers.any()); + verify(afterHook, never()).execute(Matchers.any()); + } + + @Test + public void hooks_not_executed_for_empty_pickles() throws Throwable { HookDefinition beforeHook = addBeforeHook(runtime); HookDefinition afterHook = addAfterHook(runtime); diff --git a/core/src/test/java/cucumber/runtime/HookOrderTest.java b/core/src/test/java/cucumber/runtime/HookOrderTest.java index 2b02200ea4..a6e4d8b450 100644 --- a/core/src/test/java/cucumber/runtime/HookOrderTest.java +++ b/core/src/test/java/cucumber/runtime/HookOrderTest.java @@ -38,7 +38,8 @@ public void buildMockWorld() { Runtime runtime = new Runtime(mock(ResourceLoader.class), classLoader, asList(mock(Backend.class)), runtimeOptions); runner = runtime.getRunner(); glue = runtime.getGlue(); - pickleEvent = new PickleEvent("uri", new Pickle("name", ENGLISH, Collections.emptyList(), Collections.emptyList(), asList(mock(PickleLocation.class)))); + PickleStep step = mock(PickleStep.class); + pickleEvent = new PickleEvent("uri", new Pickle("name", ENGLISH, asList(step), Collections.emptyList(), asList(mock(PickleLocation.class)))); } @Test diff --git a/core/src/test/java/cucumber/runtime/HookTest.java b/core/src/test/java/cucumber/runtime/HookTest.java index f93b6a656f..46487de930 100644 --- a/core/src/test/java/cucumber/runtime/HookTest.java +++ b/core/src/test/java/cucumber/runtime/HookTest.java @@ -39,7 +39,8 @@ public void after_hooks_execute_before_objects_are_disposed() throws Throwable { Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions); runtime.getGlue().addAfterHook(hook); Runner runner = runtime.getRunner(); - PickleEvent pickleEvent = new PickleEvent("uri", new Pickle("name", ENGLISH, Collections.emptyList(), Collections.emptyList(), asList(mock(PickleLocation.class)))); + PickleStep step = mock(PickleStep.class); + PickleEvent pickleEvent = new PickleEvent("uri", new Pickle("name", ENGLISH, asList(step), Collections.emptyList(), asList(mock(PickleLocation.class)))); runner.runPickle(pickleEvent); diff --git a/core/src/test/java/cucumber/runtime/ScenarioResultTest.java b/core/src/test/java/cucumber/runtime/ScenarioResultTest.java index 70403a8bce..362e8f7b5f 100644 --- a/core/src/test/java/cucumber/runtime/ScenarioResultTest.java +++ b/core/src/test/java/cucumber/runtime/ScenarioResultTest.java @@ -24,7 +24,13 @@ public class ScenarioResultTest { private ScenarioImpl s = new ScenarioImpl(bus, pickleEvent()); @Test - public void no_steps_is_passed() throws Exception { + public void no_steps_is_undefined() throws Exception { + assertEquals(Result.Type.UNDEFINED, s.getStatus()); + } + + @Test + public void one_passed_step_is_passed() throws Exception { + s.add(new Result(Result.Type.PASSED, 0L, null)); assertEquals(Result.Type.PASSED, s.getStatus()); }