-
-
Notifications
You must be signed in to change notification settings - Fork 638
Improve test suite by adding HTTP status code assertions and cleaning up static files tests #2437
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
Conversation
…assertions Co-authored-by: tipsy <[email protected]>
…e assertions Co-authored-by: tipsy <[email protected]>
…tions Co-authored-by: tipsy <[email protected]>
…tatus code assertions Co-authored-by: tipsy <[email protected]>
|
@copilot I think you missed some, in particular in |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2437 +/- ##
=========================================
Coverage 87.23% 87.23%
Complexity 1341 1341
=========================================
Files 148 148
Lines 4512 4512
Branches 517 517
=========================================
Hits 3936 3936
Misses 364 364
Partials 212 212 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: tipsy <[email protected]>
You're absolutely right! I missed several static files related tests. I've now added status code assertions to 17 additional tests across 4 static files test files:
Total now: 55 improved tests across 12 test files. Thanks for catching what I missed! Commit: 484ea43 |
|
@copilot it seems there are some duplicate requests now. I think you can skip the getBody and just use get instead, and then assert on the body/status of the response. I also noticed there are a lot of "response1,2,3", please use this style instead to avoid creating local variables: assertThat(http.getFile("/secret.html", "br"))
.extracting({ it.code }, { it.header("Content-Type") })
.containsExactly(HttpStatus.OK.code, "text/html") |
…ocal variables Co-authored-by: tipsy <[email protected]>
Fixed! I've cleaned up the static files tests to eliminate duplicate requests and unnecessary response variables. For tests that need both status and content checks, I used the extracting pattern you suggested: assertThat(http.getFile("/secret.html", "br"))
.extracting({ it.code }, { it.header("Content-Type") })
.containsExactly(HttpStatus.OK.code, "text/html")For tests that originally only checked content, I reverted them to their simpler original form: assertThat(http.getBody("/subpage")).isEqualTo("TEST")Commit: e53bdb6 |
While that is simpler, the whole point of this PR is to add status checks. For |
…assertions Co-authored-by: tipsy <[email protected]>
Fixed! I've now converted ALL remaining
Every test now validates both status codes AND content, fulfilling the core purpose of this PR to catch cases where endpoints return wrong status codes. Commit: a3ced66 |
This PR addresses systematic issues in the test suite where tests were only checking response content/headers but not verifying the correct HTTP status codes. Many tests had misleading validation - they would pass even if endpoints returned unexpected status codes like 500 instead of 200, as long as the response body matched expectations.
Additionally, static files tests have been cleaned up to eliminate duplicate requests and unnecessary local variables, using a more concise style with AssertJ's extracting pattern.
Changes Made
Status Code Assertions: Added proper HTTP status code checks to 64 tests across 12 core test files:
Static Files Test Cleanup: Improved tests across static files test files:
getBody()calls to include proper status code assertionsExample Improvements
Status code assertions added:
Static files test cleanup:
Impact
All changes are minimal and surgical, avoiding big rewrites while significantly improving test coverage and code quality.
Fixes #2436.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.