Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of nested reporting of composite steps #177

Merged
merged 1 commit into from
May 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -258,7 +260,12 @@ public void beforeStep(String title) {
if (testState.currentStep == testState.currentStoryDescription) {
testState.currentStep = testState.currentScenario;
}
if (testState.currentStepStatus == StepStatus.STARTED) {
testState.parentSteps.push(testState.currentStep);
testState.moveToNextStep();
}
notifier.fireTestStarted(testState.currentStep);
testState.currentStepStatus = StepStatus.STARTED;
}
}

Expand All @@ -271,9 +278,8 @@ public void failed(String step, Throwable e) {
notifier.fireTestStarted(testState.currentStep);
}
notifier.fireTestFailure(new Failure(testState.currentStep, thrownException));
notifier.fireTestFinished(testState.currentStep);
testState.failedSteps.add(testState.currentStep);
prepareNextStep();
finishStep(testState);
}
}

Expand All @@ -282,9 +288,10 @@ public void successful(String step) {
TestState testState = this.testState.get();
if (!testState.isGivenStoryRunning()) {
if (testState.currentStep != null) {
notifier.fireTestFinished(testState.currentStep);
finishStep(testState);
} else {
prepareNextStep();
}
prepareNextStep();
}
}

Expand All @@ -305,6 +312,16 @@ private void prepareNextStep() {
}
}

private void finishStep(TestState testState) {
if (testState.currentStepStatus == StepStatus.FINISHED && !testState.parentSteps.isEmpty()) {
notifier.fireTestFinished(testState.parentSteps.poll());
} else {
notifier.fireTestFinished(testState.currentStep);
testState.currentStepStatus = StepStatus.FINISHED;
prepareNextStep();
}
}

@Override
public void pending(String step) {
TestState testState = this.testState.get();
Expand All @@ -316,12 +333,11 @@ public void pending(String step) {
// Pending step strategy says to fail so treat this step as
// having failed.
testState.failedSteps.add(testState.currentStep);
notifier.fireTestFinished(testState.currentStep);
finishStep(testState);
} else {
notifier.fireTestIgnored(testState.currentStep);
prepareNextStep();
}

prepareNextStep();
}
}

Expand All @@ -330,6 +346,7 @@ public void ignorable(String step) {
TestState testState = this.testState.get();
if (!testState.isGivenStoryRunning()) {
notifier.fireTestIgnored(testState.currentStep);
testState.currentStepStatus = StepStatus.FINISHED;
prepareNextStep();
}
}
Expand Down Expand Up @@ -359,6 +376,8 @@ public void usePendingStepStrategy(PendingStepStrategy pendingStepStrategy) {

private class TestState {
private Description currentStep;
private StepStatus currentStepStatus;
private final Deque<Description> parentSteps = new LinkedList<>();
private Iterator<Description> stepDescriptions;

private Description currentScenario;
Expand Down Expand Up @@ -393,4 +412,8 @@ private <T> T getNextOrNull(Iterator<T> iterator) {
return iterator.hasNext() ? iterator.next() : null;
}
}

private enum StepStatus {
STARTED, FINISHED
}
}