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

[Feature] Reduce the amount of assertTrue/False statements #1762

Open
peternied opened this issue Apr 13, 2022 · 0 comments
Open

[Feature] Reduce the amount of assertTrue/False statements #1762

peternied opened this issue Apr 13, 2022 · 0 comments
Labels
enhancement New feature or request test fix test fixes triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable.

Comments

@peternied
Copy link
Member

peternied commented Apr 13, 2022

From #1758 (comment)

There are 1774 Assert.assertTrue(...) and and 601 Assert.assertFalse(...) statements in this codebase that are not very useful for debugging test failures. We should transition to alternatives that make test failures easier to diagnose and make tests more readable.

Consider a test case structured like this:

final String responseBody = httpClient.sendRequest('GET', '_cat');
Assert.assertTrue(body.contains("forbidden"))'

If there was a failure in this scenario it would look like

org.opensearch.security.Test > testCatApiForbidden FAILED
    org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
        at app//org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
        at app//org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:40)
        at app//org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:35)
        at app//org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:162)
        at app//org.opensearch.security.Test.testCatApiForbidden (Test.java:107)

It would be much better if the test was structured in a way that made it clearer what was wrong such as an error like org.opentest4j.AssertionFailedError: expected: <HttpStatusCode.Forbidden> but was: <HttpStatusCode.NotFound>

@peternied peternied added enhancement New feature or request test fix test fixes labels Apr 13, 2022
@davidlago davidlago added the triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable. label Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request test fix test fixes triaged Issues labeled as 'Triaged' have been reviewed and are deemed actionable.
Projects
None yet
Development

No branches or pull requests

2 participants