Skip to content

Commit 5fc9aab

Browse files
authored
Code review guidance: more explicit about deferAfterAll (#18071)
1 parent ebc273b commit 5fc9aab

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

.github/agents/code-review-and-fix.agent.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ Auto-fix boundaries:
233233
readers/writers/streams/response bodies).
234234
Do not apply this conversion in non-JUnit helper methods, `@BeforeAll`, or shared
235235
setup code.
236+
- class-scoped resources created in `@BeforeAll` or other shared setup — prefer
237+
`AutoCleanupExtension` with `deferAfterAll(...)` over nested `@AfterAll` cleanup
238+
chains. Do not introduce or keep `AutoCleanupExtension` solely for a single
239+
`deferAfterAll(...)` call — use a plain `@AfterAll` instead.
236240
- `hasAttributesSatisfying(...)` calls in test assertions — replace with
237241
`hasAttributesSatisfyingExactly(...)` because it is more precise (the non-exact
238242
variant silently ignores unexpected attributes)

.github/agents/knowledge/testing-general-patterns.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@
3333
over wrapping most of the test body in try-with-resources.
3434
- For resources created in `@BeforeAll` or other class-scoped setup, prefer
3535
`AutoCleanupExtension` with `deferAfterAll(...)` over nested `@AfterAll` cleanup
36-
chains. Prefer a single `@AfterAll` when `AutoCleanupExtension` is not otherwise present
37-
or needed in the class. Do **not** introduce `AutoCleanupExtension` solely to call
38-
`deferAfterAll(...)` once on a single resource — a plain `@AfterAll` is cleaner in that
39-
case.
36+
chains. Do not introduce or keep `AutoCleanupExtension` solely for a single
37+
`deferAfterAll(...)` call — use a plain `@AfterAll` instead.
4038
- Reuse an existing `cleanup` extension when one is already in scope.
4139
Otherwise, add a `@RegisterExtension` field when the deferred-cleanup pattern improves
4240
clarity or avoids wrapping most of the test body.

0 commit comments

Comments
 (0)