Skip to content

docs: add TESTING.md with testing conventions for contributors#3718

Open
sandikodev wants to merge 2 commits intoaws:mainfrom
sandikodev:docs/testing-conventions
Open

docs: add TESTING.md with testing conventions for contributors#3718
sandikodev wants to merge 2 commits intoaws:mainfrom
sandikodev:docs/testing-conventions

Conversation

@sandikodev
Copy link
Copy Markdown

Motivation

The codebase has insta as a workspace dependency but its usage is minimal (3 occurrences across the entire codebase) and completely undocumented. There is currently no guidance for contributors on:

  • When to use assert_eq!/assert! vs insta snapshot testing
  • How to run the cargo insta review workflow
  • How to handle ANSI escape codes in terminal output tests (a common pitfall when testing rendering functions like print_diff)

This gap leads to either fragile hardcoded strings or missing tests for rendered output entirely.

Changes

  • Add TESTING.md at the repo root with:
    • Quick reference table for choosing the right assertion style
    • Standard assertion examples with guidance on when they are appropriate
    • Full cargo-insta workflow: write → run → review → accept
    • Pattern for stripping ANSI escape codes before asserting
    • Real example referencing the pattern introduced in PR fix(fs_write): suppress spurious trailing-newline diff lines #3717
  • Add a one-line pointer in CONTRIBUTING.mdTESTING.md

Notes

  • docs/ was intentionally left unchanged — all existing files there are user-facing feature documentation, not contributor guides
  • TESTING.md follows the same root-level convention as CONTRIBUTING.md, SECURITY.md, and CODE_OF_CONDUCT.md

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The codebase has insta as a workspace dependency but its usage is
minimal and undocumented. Contributors currently have no guidance on:
- when to use assert_eq!/assert! vs insta snapshot testing
- how to run the cargo-insta review workflow
- how to handle ANSI escape codes in terminal output tests

Add TESTING.md at the repo root covering:
- Quick reference table for choosing assertion style
- Standard assertion examples
- Full insta workflow (write -> run -> review -> accept)
- ANSI escape code stripping pattern
- Real example referencing the pattern used in PR aws#3717

Add a one-line pointer in CONTRIBUTING.md.
…nd real examples

- Add Table of Contents
- Add Core Principle section explaining the decision framework
- Expand Quick Reference table with JSON and 'output may change' rows
- Add explicit do/don't examples for standard assertions
- Document all three insta modes (inline, auto-named, named)
- Add note to install cargo-insta before writing snapshot tests
- Add note that strip_ansi_escapes is already in the workspace
- Add Case 2: sanitize_path_tool_arg as a second real example
- Expand Anti-Patterns with context on why each is problematic
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

Successfully merging this pull request may close these issues.

1 participant