TestRunner: before_all, before_each, after_each, after_all hooks #10

Closed
opened 2026-04-11 10:55:39 +00:00 by charles · 0 comments
Owner

User story

As a test author, I want lifecycle hooks for fixture setup and per-test cleanup, so that state can be reset between tests without duplicated boilerplate in every test body.

Acceptance criteria

  • runner.before_all(|client| async move { ... }) — runs once after harness start, before any tests. Failure aborts the run with a clear error.
  • runner.before_each(|client| async move { ... }) — runs before every selected test. Failure marks that test as failed and skips its body; after_each still runs.
  • runner.after_each(|client| async move { ... }) — runs after every selected test, regardless of pass/fail. Failure is logged but does not change the test outcome (the original test result wins).
  • runner.after_all(|client| async move { ... }) — runs once after all tests, before harness stop. Failure is logged and surfaces in the report (report.after_all_failed: bool) and exit code.
  • All hooks receive Arc<RpcClient> and return impl Future<Output = TestResult>.
  • Each hook is optional; absence is a no-op.
  • Self-tests cover all four hooks plus the failure paths.

Why all four

The original spec only listed before_each and after_all, which leaves common patterns awkward:

  • before_all for one-time fixture seeding (resolves spec review §4).
  • after_each for per-test cleanup that's better done after rather than before (resolves spec review §5).

References

  • Spec §4.3; spec review §4 and §5
## User story As a **test author**, I want lifecycle hooks for fixture setup and per-test cleanup, so that state can be reset between tests without duplicated boilerplate in every test body. ## Acceptance criteria - [ ] `runner.before_all(|client| async move { ... })` — runs once after harness start, before any tests. Failure aborts the run with a clear error. - [ ] `runner.before_each(|client| async move { ... })` — runs before every selected test. Failure marks **that test** as failed and skips its body; `after_each` still runs. - [ ] `runner.after_each(|client| async move { ... })` — runs after every selected test, regardless of pass/fail. Failure is logged but does **not** change the test outcome (the original test result wins). - [ ] `runner.after_all(|client| async move { ... })` — runs once after all tests, before harness stop. Failure is logged and surfaces in the report (`report.after_all_failed: bool`) and exit code. - [ ] All hooks receive `Arc<RpcClient>` and return `impl Future<Output = TestResult>`. - [ ] Each hook is **optional**; absence is a no-op. - [ ] Self-tests cover all four hooks plus the failure paths. ## Why all four The original spec only listed `before_each` and `after_all`, which leaves common patterns awkward: - **`before_all`** for one-time fixture seeding (resolves spec review §4). - **`after_each`** for per-test cleanup that's better done after rather than before (resolves spec review §5). ## References - Spec §4.3; spec review §4 and §5
charles added this to the v0.1.0 milestone 2026-04-11 10:55:39 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/ws-rpc-test#10
No description provided.