diff --git a/README.md b/README.md index 458e762..7cb4b75 100644 --- a/README.md +++ b/README.md @@ -81,3 +81,4 @@ In the IDE reporting is shown: | 4.8.0 | 4.8 | | 4.8.3 | 4.8.3 | | 5.0.0 | 5.0 | +| 5.0.1 | 5.0 | diff --git a/src/main/java/org/jbehavesupport/engine/reporter/StepLoggingReporter.java b/src/main/java/org/jbehavesupport/engine/reporter/StepLoggingReporter.java index 2dc4efe..aa7f89e 100644 --- a/src/main/java/org/jbehavesupport/engine/reporter/StepLoggingReporter.java +++ b/src/main/java/org/jbehavesupport/engine/reporter/StepLoggingReporter.java @@ -21,6 +21,7 @@ import org.jbehave.core.configuration.Configuration; import org.jbehave.core.failures.PendingStepFound; import org.jbehave.core.failures.UUIDExceptionWrapper; +import org.jbehave.core.model.Lifecycle; import org.jbehave.core.model.Scenario; import org.jbehave.core.model.Step; import org.jbehave.core.model.Story; @@ -57,6 +58,8 @@ public class StepLoggingReporter extends AbstractLoggingReporter { private Deque currentStepDescriptor = new ArrayDeque<>(); private boolean isInBeforeStories = false; + private boolean isInBeforeScenario = false; + private boolean isInAfterScenario = false; private boolean isInAfterStories = false; private boolean isInMainScenario = false; @@ -170,6 +173,32 @@ public void beforeScenario(Scenario scenario) { } } + @Override + public void beforeScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType cycle){ + // as in jbehave-core v5.0: + // Always trigger StoryReporter.beforeStep(Step) hook and report all outcomes (previously only failures were reported, successful outcome was silent) for methods annotated with @BeforeStories, @AfterStories, @BeforeStory, @AfterStory, @BeforeScenario, @AfterScenario + // @BeforeScenario steps are executed between cycle SYSTEM and stage BEFORE and next stage, so we won't report steps in this combination + if (cycle == Lifecycle.ExecutionType.SYSTEM && stage == StepCollector.Stage.BEFORE) { + isInBeforeScenario = true; + } else { + isInBeforeScenario = false; + } + super.beforeScenarioSteps(stage, cycle); + } + + @Override + public void afterScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType cycle){ + // as in jbehave-core v5.0: + // Always trigger StoryReporter.beforeStep(Step) hook and report all outcomes (previously only failures were reported, successful outcome was silent) for methods annotated with @BeforeStories, @AfterStories, @BeforeStory, @AfterStory, @BeforeScenario, @AfterScenario + // @AfterScenario steps are executed between cycle USER and stage AFTER and next stage, so we won't report steps in this combination + if (cycle == Lifecycle.ExecutionType.USER && stage == StepCollector.Stage.AFTER) { + isInAfterScenario = true; + } else if (cycle == Lifecycle.ExecutionType.SYSTEM && stage == StepCollector.Stage.AFTER) { + isInAfterScenario = false; + } + super.beforeScenarioSteps(stage, cycle); + } + private List getAllExamples(Set children) { List result = new ArrayList<>(); for (TestDescriptor child : children) { @@ -201,7 +230,7 @@ private List getAllChildren(Set childr @Override public void afterScenario(Timing timing) { super.afterScenario(timing); - if (shouldReportStep()) { + if (notAGivenStory() && (!isInBeforeStories || !isInAfterStories)) { engineExecutionListener.executionFinished(currentScenarioDescriptor, TestExecutionResult.successful()); // main scenario starts before given stories are run, // so we need to handle the case of afterScenario of given story @@ -290,9 +319,12 @@ public void ignorable(String step) { private boolean shouldReportStep() { // not a given story // not in before stories or after stories + // not in before scenario or after scenario // and is in scenario of the main story (e.g. not some custom before story hook on method or something like that) return notAGivenStory() && (!isInBeforeStories || !isInAfterStories) + && !isInBeforeScenario + && !isInAfterScenario && isInMainScenario; } diff --git a/src/main/java/org/jbehavesupport/runner/reporter/JUnitStepReporter.java b/src/main/java/org/jbehavesupport/runner/reporter/JUnitStepReporter.java index 0f415d3..30c8f12 100644 --- a/src/main/java/org/jbehavesupport/runner/reporter/JUnitStepReporter.java +++ b/src/main/java/org/jbehavesupport/runner/reporter/JUnitStepReporter.java @@ -20,6 +20,7 @@ import org.jbehave.core.configuration.Configuration; import org.jbehave.core.failures.UUIDExceptionWrapper; +import org.jbehave.core.model.Lifecycle; import org.jbehave.core.model.Scenario; import org.jbehave.core.model.Step; import org.jbehave.core.model.Story; @@ -53,6 +54,8 @@ public class JUnitStepReporter extends AbstractJUnitReporter { private Deque currentStepDescription = new ArrayDeque<>(); private boolean isInBeforeStories = false; + private boolean isInBeforeScenario = false; + private boolean isInAfterScenario = false; private boolean isInAfterStories = false; private boolean isInMainScenario = false; @@ -165,6 +168,32 @@ public void beforeScenario(Scenario scenario) { } } + @Override + public void beforeScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType cycle){ + // as in jbehave-core v5.0: + // Always trigger StoryReporter.beforeStep(Step) hook and report all outcomes (previously only failures were reported, successful outcome was silent) for methods annotated with @BeforeStories, @AfterStories, @BeforeStory, @AfterStory, @BeforeScenario, @AfterScenario + // @BeforeScenario steps are executed between cycle SYSTEM and stage BEFORE and next stage, so we won't report steps in this combination + if (cycle == Lifecycle.ExecutionType.SYSTEM && stage == StepCollector.Stage.BEFORE) { + isInBeforeScenario = true; + } else { + isInBeforeScenario = false; + } + super.beforeScenarioSteps(stage, cycle); + } + + @Override + public void afterScenarioSteps(StepCollector.Stage stage, Lifecycle.ExecutionType cycle){ + // as in jbehave-core v5.0: + // Always trigger StoryReporter.beforeStep(Step) hook and report all outcomes (previously only failures were reported, successful outcome was silent) for methods annotated with @BeforeStories, @AfterStories, @BeforeStory, @AfterStory, @BeforeScenario, @AfterScenario + // @AfterScenario steps are executed between cycle USER and stage AFTER and next stage, so we won't report steps in this combination + if (cycle == Lifecycle.ExecutionType.USER && stage == StepCollector.Stage.AFTER) { + isInAfterScenario = true; + } else if (cycle == Lifecycle.ExecutionType.SYSTEM && stage == StepCollector.Stage.AFTER) { + isInAfterScenario = false; + } + super.beforeScenarioSteps(stage, cycle); + } + private List getAllExamples(ArrayList children) { List result = new ArrayList<>(); for (Description child : children) { @@ -196,7 +225,7 @@ private List getAllChildren(ArrayList children, List