Skip to content

Commit

Permalink
notify step failure in StepInterceptor if soft assertion enabled (#3402)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-rd authored Feb 9, 2024
1 parent 39e296a commit 81a8635
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private Object runTestStep(final Object obj, final Method method,
}

private void logStepFailure(Object object, Method method, Object[] args, Throwable assertionError) throws Throwable {
if (StepEventBus.getEventBus().aStepInTheCurrentTestHasFailed()) {
if (StepEventBus.getEventBus().aStepInTheCurrentTestHasFailed() && !StepEventBus.getEventBus().softAssertsActive()) {
return;
}
notifyOfStepFailure(object, method, args, assertionError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,31 @@ public void a_failing_step_should_record_the_failure_details_with_the_step() {
assertThat(testOutcome.getTestSteps().get(1).getErrorMessage(), containsString("Step failed"));
}

@Test
public void a_failing_step_should_not_prevent_collecting_next_steps_result_if_soft_asserts_enabled() throws Exception {

StepEventBus.getParallelEventBus().testSuiteStarted(MyTestCase.class);
StepEventBus.getParallelEventBus().testStarted("app_should_work");
StepEventBus.getParallelEventBus().enableSoftAsserts();

FlatScenarioSteps steps = stepFactory.getSharedStepLibraryFor(FlatScenarioSteps.class);
steps.step_one();
steps.failingWithExceptionStep();
steps.step_two();
steps.failingWithExceptionStep();
steps.step_three();
StepEventBus.getParallelEventBus().testFinished(testOutcome);

List<TestOutcome> results = stepListener.getTestOutcomes();
TestOutcome testOutcome = results.get(0);

assertThat(testOutcome.getTestSteps().size(), equalTo(5));
TestResult[] expectedResults = {TestResult.SUCCESS, TestResult.ERROR, TestResult.SUCCESS, TestResult.ERROR, TestResult.SUCCESS};
for (int i = 0; i < testOutcome.getTestSteps().size(); i++) {
assertThat(testOutcome.getTestSteps().get(i).getResult(), is(expectedResults[i]));
}
}

@Test
public void ignored_tests_should_be_reported() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void failingStep() {
throw new AssertionError("Step failed");
}

@Step
public void failingWithExceptionStep() throws Exception {
throw new Exception("Step failed due to exception");
}

@Ignore
@Step
public void ignoredStep() {}
Expand Down

0 comments on commit 81a8635

Please sign in to comment.