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

Final test result is incorrect when execution with JUnit throws exception #3298

Closed
grey-rain opened this issue Oct 21, 2023 · 0 comments
Closed

Comments

@grey-rain
Copy link
Contributor

grey-rain commented Oct 21, 2023

What happened?

The bug has been reported for integration I work on. When common exception is thrown from test, tests are considered PASSED by net.serenitybdd.junit5.SerenityTestExecutionListener#testFinished.

What did you expect to happen?

Both tests status should be updated to FAILED by net.serenitybdd.junit5.SerenityTestExecutionListener#testFinished.

Serenity BDD version

2.3.4, 4.0.8

JDK version

11

Execution environment

No response

How to reproduce the bug.

@slf4j
@ExtendWith(SerenityJUnit5Extension.class)
class TestXXX {

@Test
void test1() {
    log.info(">run 1");
    throw new RuntimeException("fail");
}

@Test
void test2() {
    log.info(">run 2");
    assertThat(1).isEqualTo(2);
}

How can we make it happen?

Work on this myself and propose a PR (with Serenity BDD team guidance)

Note

I made some digging here. It appeared the issue is with lines 357-359 of net.serenitybdd.junit5.SerenityTestExecutionListener#testFinished: if clause appears to be false in those 2 cases.

} else if (testExecutionResult.getStatus() == TestExecutionResult.Status.FAILED && result.isLessSevereThan(TestResult.FAILURE)) {
            updateResultsUsingTestExecutionResult(testIdentifier, testExecutionResult);
        }

This chain leads to result.isLessSevereThan and result.isMoreSevereThan not seeming to work as expected by its naming (they're currently opposite). The reason is that those methods use ordinal() to compare enum values, however, values are ordered not in expected state for it to work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant