agentleFS
las-pinterlas-pinter/persona-agents/skills/tester/test-case-structure/SKILL.md

test-case-structure

Skill2 starsChanged 2 months agoMITView on GitHub

Language-agnostic structure, naming conventions, and rules for writing clear, maintainable test cases.

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
  1. Distinctive:

    Describe behavior, not implementation: Test names say WHAT the code does, not HOW.

    line 10
  2. Distinctive:

    Readability over convention: If a longer name is clearer, use it.

    line 12
  3. Distinctive:

    Use AAA for developer-facing unit tests.

    line 85
  4. Distinctive:

    Use unique values for unique-constrained fields (timestamp/UUID suffix)

    line 100
  5. Distinctive:

    Never use production data in tests — use Faker for synthetic data

    line 102
  6. Distinctive:

    Use the most specific assertion available

    line 116
  7. Very specific:

    Use soft assertions / assertAll to report ALL failures, not just the first

    line 117
  8. Distinctive:

    Use when: same logic across multiple input/output pairs.

    line 123
  9. Very specific:

    Never use sleep(): All waits must be condition-based with explicit timeouts.

    line 177
  10. Distinctive:

    If not fixed in deadline: delete it — an untrusted test is a liability

    line 182

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Test Case Structure

Universal Principles

  1. Describe behavior, not implementation. Test names say WHAT the code does, not HOW.
  2. Every test name answers three questions: What context/input? What action? What outcome?
  3. 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_error

Pattern 2: Condition-Outcome

Best for: simple, single-condition scenarios.

// JS:   it('rejects payment when balance insufficient')
# Python: test_insufficient_balance_rejects_payment

Pattern 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 outcome

Rules:

  • 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:

AAAGWT
ArrangeGiven
ActWhen
AssertThen

Use AAA for developer-facing unit tests. Use GWT for stakeholder-facing acceptance tests.


Test Data Management

PatternBest ForKey Rule
FixturesReference data; read-only testsOnly for data tests READ but never MODIFY
FactoriesEach test creates its own dataDefaults must be valid with no overrides
BuildersComplex objects with many optional fieldsImmutable 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

  1. Assert the exact desired behavior — not more (brittle), not less (misses regressions)
  2. One assertion per logical concept; multiple asserts OK when verifying different aspects of the SAME behavior
  3. Assert requirements, not implementation — test should survive refactoring
  4. Use the most specific assertion available
  5. Use soft assertions / assertAll to report ALL failures, not just the first

Parameterized Testing

Use when: same logic across multiple input/output pairs; edge case coverage; combinatorial scenarios.

FrameworkSimple CasesComplex 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")
Jestit.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

TypePurposeVerifies
DummyFills parameter lists; never calledNothing
FakeWorking but simplified implementationState after interaction
StubReturns canned answersIndirect inputs
SpyRecords calls for later verificationIndirect outputs
MockPre-programmed expectationsBehavior (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

LanguageNamingStructure
Pythontest_behavior_when_contextAAA with blank-line separation
JS/TSit('behavior when context')describe/it blocks
Java@DisplayName("behavior") + methodJUnit 5 with assertAll
GoTestBehaviorWhenContext(t *testing.T)Table-driven tests

Flaky Test Prevention

CauseFrequencyFix
Async wait issues~45%Replace sleep() with condition-based waits + explicit timeouts
Shared state pollutionCommonEach test creates its own data; transaction rollback
Test order dependenciesCommonRandomize test order; each test self-contained
Non-deterministic dataCommonFixed seeds; mock time/random

Never use sleep(). All waits must be condition-based with explicit timeouts.

Quarantine Protocol for Flaky Tests

  1. Move to a non-blocking quarantine suite
  2. Assign owner + two-week deadline to fix
  3. If not fixed in deadline: delete it — an untrusted test is a liability

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.