Unit Test Patterns
When writing test vectors in cookbook artifacts (ingredients and recipes), structure them as Arrange-Act-Assert specifications so that code generators produce well-structured test code.
Test vector structure
Each test vector in a cookbook artifact SHOULD follow the Arrange-Act-Assert pattern:
- Arrange — describe the preconditions and input state
- Act — describe the action or method call being tested
- Assert — describe the expected outcome
Rules for test vectors
- Each vector MUST test one behavioral concept — not multiple unrelated assertions
- Vectors MUST NOT depend on each other — each is self-contained
- Vectors SHOULD target the public API described in the artifact's requirements, not implementation details
Naming test vectors
Use descriptive names that read as specifications:
test_parse_order_with_valid_json_returns_orderParseOrder_WithMissingField_ThrowsValidationError"returns empty list when no results match"
These names will be used verbatim by code generators, so they MUST be clear enough to serve as test documentation.