test-case-structure
Skill2 starsChanged 2 months agoMITView on GitHub
Language-agnostic structure, naming conventions, and rules for writing clear, maintainable test cases.
In this repository18 other files it gives its agents.
- AGENTS.mdAGENTS.md
- journal-management-genericSkill
- simplified-technical-englishSkill
- code-implementationSkill
- python-quality-gatesSkill
- journal-managementSkill
- plan-trackingSkill
- project-notesSkill
- task-routingSkill
- herdrSkill
- plan-output-templateSkill
- risk-and-dependency-identificationSkill
- task-decompositionSkill
- source-selectionSkill
- code-review-checklistSkill
- production-issue-flaggingSkill
- regression-identificationSkill
- test-strategy-selectionSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 8 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Describe behavior, not implementation: Test names say WHAT the code does, not HOW.
- Distinctive: line 12
Readability over convention: If a longer name is clearer, use it.
- Distinctive: line 85
Use AAA for developer-facing unit tests.
- Distinctive: line 100
Use unique values for unique-constrained fields (timestamp/UUID suffix)
- Distinctive: line 102
Never use production data in tests — use Faker for synthetic data
- Distinctive: line 116
Use the most specific assertion available
- Very specific: line 117
Use soft assertions / assertAll to report ALL failures, not just the first
- Distinctive: line 123
Use when: same logic across multiple input/output pairs.
- Very specific: line 177
Never use
sleep(): All waits must be condition-based with explicit timeouts. - Distinctive: line 182
If not fixed in deadline: delete it — an untrusted test is a liability
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Test Case Structure
Universal Principles
- Describe behavior, not implementation. Test names say WHAT the code does, not HOW.
- Every test name answers three questions: What context/input? What action? What outcome?
- Readability over convention. If a longer name is clearer, use it.
Good vs Bad Names
❌ Implementation-focused: callsDatabaseQuery, loopsThroughArray, verifyServiceIsCalled
✅ Behavior-focused: returnsUserWhenIdExists, rejectsPaymentWhenBalanceInsufficient, returnsEmptyListWhenNoResultsFound
Naming Patterns
Pattern 1: Given-When-Then
Best for: complex scenarios with multiple preconditions.
// JS: it('returns error when cart is empty')
# Python: test_given_empty_cart_when_checkout_then_raises_errorPattern 2: Condition-Outcome
Best for: simple, single-condition scenarios.
// JS: it('rejects payment when balance insufficient')
# Python: test_insufficient_balance_rejects_paymentPattern 3: Nested Context (recommended for complex flows)
Eliminates redundancy by grouping related scenarios:
describe('Payment Processing')
describe('when credit card is valid')
it('completes transaction successfully')
it('sends confirmation email')
describe('when credit card is expired')
it('rejects the transaction')
it('returns descriptive error message')What to Avoid
- Fluff words: "correctly", "properly", "valid" (unless exact scenario name)
- Redundant prefixes: "test" (unless framework requires it)
- Implementation details in names: exception types, method names
- Multiple scenarios in one test — split them
- Magic values:
test_returns_42→test_returns_max_items_per_page
Test Structure
Arrange-Act-Assert (AAA)
// Arrange — set up test data and preconditions
// Act — execute the behavior under test
// Assert — verify the outcomeRules:
- One Act per test — multiple actions make failure diagnosis ambiguous
- Arrange sets up only what's needed for THIS test
- Assert verifies the outcome, not intermediate state
- Separate phases with blank lines or comments for readability
Given-When-Then (GWT)
Semantically identical to AAA, framed for behavior:
| AAA | GWT |
| Arrange | Given |
| Act | When |
| Assert | Then |
Use AAA for developer-facing unit tests. Use GWT for stakeholder-facing acceptance tests.
Test Data Management
| Pattern | Best For | Key Rule |
| Fixtures | Reference data; read-only tests | Only for data tests READ but never MODIFY |
| Factories | Each test creates its own data | Defaults must be valid with no overrides |
| Builders | Complex objects with many optional fields | Immutable pattern prevents shared state |
Golden Rules
- Each test creates its own data — never depend on data from other tests
- Override only what matters for the specific test scenario
- Use unique values for unique-constrained fields (timestamp/UUID suffix)
- Clean up between tests — transaction rollback is ideal
- Never use production data in tests — use Faker for synthetic data
Anti-Patterns
- ❌ Hardcoded IDs (
id = 1) — break when database resets - ❌ Shared global seed files — invisible dependencies between tests
- ❌ Over-seeding in
beforeEach— every test becomes slow and unclear
Assertion Patterns
- Assert the exact desired behavior — not more (brittle), not less (misses regressions)
- One assertion per logical concept; multiple asserts OK when verifying different aspects of the SAME behavior
- Assert requirements, not implementation — test should survive refactoring
- Use the most specific assertion available
- Use soft assertions /
assertAllto report ALL failures, not just the first
Parameterized Testing
Use when: same logic across multiple input/output pairs; edge case coverage; combinatorial scenarios.
| Framework | Simple Cases | Complex Cases |
| pytest | @pytest.mark.parametrize("input,expected", [(1,2)]) | pytest.param(1, 2, id="case_name") |
| JUnit 5 | @CsvSource({"1,2", "3,4"}) | @MethodSource("dataProvider") |
| Jest | it.each([[1, 2], [3, 4]]) | it.each with template literals |
Pitfalls:
- ❌ Logic in test body to handle different parameter sets differently (if/switch on parameter)
- ❌ Arrays of different lengths — zip silently drops cases
- ❌ Data extracted far from the test body — hurts readability
Test Doubles
| Type | Purpose | Verifies |
| Dummy | Fills parameter lists; never called | Nothing |
| Fake | Working but simplified implementation | State after interaction |
| Stub | Returns canned answers | Indirect inputs |
| Spy | Records calls for later verification | Indirect outputs |
| Mock | Pre-programmed expectations | Behavior (was it called correctly?) |
Use doubles for: external systems, slow dependencies, non-deterministic services. Do NOT use doubles for: value objects, simple domain logic, immutable data.
Prefer order: Fakes → Stubs/Spies → Mocks. Use mocks only when the interaction contract matters.
Over-mocking couples tests to implementation — the #1 anti-pattern in test doubles.
Language Conventions
| Language | Naming | Structure |
| Python | test_behavior_when_context | AAA with blank-line separation |
| JS/TS | it('behavior when context') | describe/it blocks |
| Java | @DisplayName("behavior") + method | JUnit 5 with assertAll |
| Go | TestBehaviorWhenContext(t *testing.T) | Table-driven tests |
Flaky Test Prevention
| Cause | Frequency | Fix |
| Async wait issues | ~45% | Replace sleep() with condition-based waits + explicit timeouts |
| Shared state pollution | Common | Each test creates its own data; transaction rollback |
| Test order dependencies | Common | Randomize test order; each test self-contained |
| Non-deterministic data | Common | Fixed seeds; mock time/random |
Never use sleep(). All waits must be condition-based with explicit timeouts.
Quarantine Protocol for Flaky Tests
- Move to a non-blocking quarantine suite
- Assign owner + two-week deadline to fix
- If not fixed in deadline: delete it — an untrusted test is a liability
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

