tdd-xunit-patterns

Installation
SKILL.md

xUnit Patterns

An xUnit framework gives you a small vocabulary: assertions, fixtures, setup and teardown, test methods and suites. Use each one for the job it was built for, so every test is automatic, specific, isolated and easy to read.

Assertion

Problem: how do you check that a test worked without a human judging the output? Answer: write boolean expressions that the computer checks through an assert call.

  • Every judgment must be automated. True means everything is fine. False means something unexpected happened.
  • Be specific. assert area != 0 passes for almost any wrong answer. If the area should be 50, assert that it equals 50.
  • Prefer the framework's equality assertion. It prints the expected and actual values on failure. Follow the framework's argument order (JUnit puts expected first; in pytest you write actual == expected).
  • Use floating-point assertions with an explicit tolerance.
  • Assert through the public protocol, not private fields or internal types. A test that checks contract.status is a Running instance breaks when the representation changes. Assert on observable behavior instead (for example, that contract.start_date() is now available).
  • Wanting to inspect a private variable is a design signal, not a testing problem. Look for the design change that would make the behavior observable. If none comes to mind, check the variable, leave a note to revisit it, and move on.
  • Failure messages: some teams require an explanatory message on every assertion. Try it both ways and keep messages where they actually speed up diagnosis.
Installs
1
First Seen
2 days ago