Back to list
rubrical-studios

test-writing-patterns

by rubrical-studios

GitHub CLI extension for project management, sub-issue hierarchies, and batch operations

1🍴 0📅 Jan 25, 2026

SKILL.md


name: test-writing-patterns description: Guide experienced developers on test structure, patterns, assertions, and test doubles for effective test-driven development license: Complete terms in LICENSE.txt

Test Writing Patterns

Version: {{VERSION}}

When to Use

  • User needs guidance on test structure
  • Questions about test organization
  • Need test double (mock/stub/fake) guidance
  • Uncertainty about assertion strategies

Test Structure Patterns

AAA Pattern (Arrange-Act-Assert)

ARRANGE: Set up test conditions and inputs
ACT: Execute the behavior being tested
ASSERT: Verify the expected outcome

Given-When-Then Pattern (BDD Style)

GIVEN: Initial context/preconditions
WHEN: Action/event occurs
THEN: Expected outcomes

Test Organization

File Organization

Production:
  src/services/user_service

Tests:
  tests/services/test_user_service

Test Naming

test_[unit]_[scenario]_[expected]

Examples:
- test_add_positive_numbers_returns_sum
- test_get_user_when_not_found_returns_null

Assertion Strategies

Single Concept Per Test

Good: All assertions verify the same concept Poor: Multiple unrelated assertions in one test

Common Assertion Types

  • Equality: assert actual == expected
  • Truthiness: assert condition is true
  • Comparison: assert value > 0
  • Collection: assert item in collection
  • Exception: assert raises(ExpectedException)

Test Doubles

Types

TypePurposeWhen to Use
StubProvide predetermined responsesControl dependency behavior
MockVerify interactions/callsCheck method was called
FakeWorking simplified implementationIntegration testing
SpyRecord calls while delegatingNeed real behavior + verification

Selection Guide

Need to control response? -> Stub
Need to verify call made? -> Mock
Need working but simple version? -> Fake
Need real behavior + verification? -> Spy

Test Isolation

Each test should:

  • Set up its own data
  • Clean up after itself
  • Run in any order
  • Not depend on other tests

Test Data Strategies

Explicit Test Data

Good: user = create_user(name="Alice", age=30)
Poor: user = create_user(name=random_string())

Minimal Test Data

Use simplest data that tests the behavior.

Testing Strategies by Type

Unit Tests

  • Test single unit
  • Fast execution
  • No external dependencies

Integration Tests

  • Test multiple units together
  • May use real dependencies

End-to-End Tests

  • Test complete user workflows
  • Use real system

Test Coverage

Coverage shows:

  • Which code is executed by tests
  • Which code is NOT executed

Coverage does NOT mean:

  • All behaviors tested
  • Tests are good quality
  • Code is correct

Test Smells

SmellFix
Test does too muchSplit into focused tests
Tests are brittleTest behavior, not implementation
Tests are slowUse test doubles, optimize setup
Tests are unclearBetter naming, clear AAA structure
Tests depend on each otherEnsure test isolation

Parameterized Tests

test_add_numbers:
  parameters:
    (2, 3, 5)
    (-2, -3, -5)
    (0, 0, 0)

  for each (a, b, expected):
    assert add(a, b) == expected

Resources

  • resources/aaa-pattern-template.md
  • resources/test-doubles-guide.md
  • resources/assertion-patterns.md
  • resources/test-organization-examples.md

End of Test Writing Patterns Skill

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon