agentsclimarketplace

Testing patterns

Skill bg-szy/TOP-SKILLS/skills/marketplace/testing-patterns

全球最大的 Claude Code 技能聚合库 · 收录 3900+ 来自 12+ 来源的技能,提供在线搜索与趋势分析看板 / The world's largest Claude Code skill aggregation hub — 3900+ skills from 12+ sources with online search and trend dashboard

Install
npx -y skills add bg-szy/TOP-SKILLS --skill testing-patterns

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Cross-language testing strategies and patterns. Triggers on: test pyramid, unit test, integration test, e2e test, TDD, BDD, test coverage, mocking strategy, test doubles, test isolation.

SKILL.md

4.1 KB, as published. Nobody here has run it

Testing Patterns

Universal testing strategies and patterns applicable across languages.

The Test Pyramid

        /\
       /  \     E2E Tests (few, slow, expensive)
      /    \    - Full system tests
     /------\   - Real browser/API calls
    /        \
   /  Integ   \ Integration Tests (some)
  /   Tests    \ - Service boundaries
 /--------------\ - Database, APIs
/                \
/   Unit Tests    \ Unit Tests (many, fast, cheap)
------------------  - Single function/class
                    - Mocked dependencies

Test Types

Unit Tests

Scope:      Single function/method/class
Speed:      Milliseconds
Dependencies: All mocked
When:       Every code change
Coverage:   80%+ of codebase

Integration Tests

Scope:      Multiple components together
Speed:      Seconds
Dependencies: Real databases, mocked external APIs
When:       PR/merge, critical paths
Coverage:   Key integration points

End-to-End Tests

Scope:      Full user journey
Speed:      Minutes
Dependencies: Real system (or staging)
When:       Pre-deploy, nightly
Coverage:   Critical user flows only

Test Naming Convention

test_<unit>_<scenario>_<expected>

Examples:
- test_calculate_total_with_discount_returns_reduced_price
- test_user_login_with_invalid_password_returns_401
- test_order_submit_when_out_of_stock_raises_error

Arrange-Act-Assert (AAA)

def test_calculate_discount():
    # Arrange - Set up test data and dependencies
    cart = Cart()
    cart.add_item(Item(price=100))
    discount = Discount(percent=10)

    # Act - Execute the code under test
    total = cart.calculate_total(discount)

    # Assert - Verify the results
    assert total == 90

Test Doubles

TypePurposeExample
StubReturns canned datastub.get_user.returns(fake_user)
MockVerifies interactionsmock.send_email.assert_called_once()
SpyRecords calls, uses real implspy.on(service, 'save')
FakeWorking simplified implFakeDatabase() instead of real DB
DummyPlaceholder, never usednull object for required param

Test Isolation Strategies

Database Isolation

Option 1: Transaction rollback (fast)
- Start transaction before test
- Rollback after test

Option 2: Truncate tables (medium)
- Clear all data between tests

Option 3: Separate database (slow)
- Each test gets fresh database

External Service Isolation

Option 1: Mock at boundary
- Replace HTTP client with mock

Option 2: Fake server
- WireMock, MSW, VCR cassettes

Option 3: Contract testing
- Pact, consumer-driven contracts

What to Test

MUST Test

  • Business logic and calculations
  • Input validation and error handling
  • Security-sensitive code (auth, permissions)
  • Edge cases and boundary conditions

SHOULD Test

  • Integration points (DB, APIs)
  • State transitions
  • Configuration handling

AVOID Testing

  • Framework internals
  • Third-party library behavior
  • Simple getters/setters
  • Private implementation details

Test Quality Checklist

  • Tests are independent (no order dependency)
  • Tests are deterministic (no flaky tests)
  • Tests are fast (unit < 100ms, integration < 5s)
  • Tests have clear names describing behavior
  • Tests cover happy path AND error cases
  • Tests don't repeat production logic
  • Mocks are minimal (only external boundaries)

Additional Resources

  • ./references/tdd-workflow.md - Test-Driven Development cycle
  • ./references/mocking-strategies.md - When and how to mock
  • ./references/test-data-patterns.md - Fixtures, factories, builders
  • ./references/ci-testing.md - Testing in CI/CD pipelines

Scripts

  • ./scripts/coverage-check.sh - Run coverage and fail if below threshold

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.