Skip to content
cccskills
FreePublished on GitHub

testing-patterns

Testing patterns and principles. Unit, integration, mocking strategies.

The English summary is being prepared. Showing the original description.

See how to install

Files included (2)

  • SKILL.md3.4 KB
  • scripts/test_runner.py6.9 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Testing Patterns

Principles for reliable test suites.


1. Testing Pyramid

        /\          E2E (Few)
       /  \         Critical flows
      /----\
     /      \       Integration (Some)
    /--------\      API, DB queries
   /          \
  /------------\    Unit (Many)
                    Functions, classes

2. AAA Pattern

StepPurpose
ArrangeSet up test data
ActExecute code under test
AssertVerify outcome

3. Test Type Selection

When to Use Each

TypeBest ForSpeed
UnitPure functions, logicFast (<50ms)
IntegrationAPI, DB, servicesMedium
E2ECritical user flowsSlow

4. Unit Test Principles

Good Unit Tests

PrincipleMeaning
Fast< 100ms each
IsolatedNo external deps
RepeatableSame result always
Self-checkingNo manual verification
TimelyWritten with code

What to Unit Test

TestDon't Test
Business logicFramework code
Edge casesThird-party libs
Error handlingSimple getters

5. Integration Test Principles

What to Test

AreaFocus
API endpointsRequest/response
DatabaseQueries, transactions
External servicesContracts

Setup/Teardown

PhaseAction
Before AllConnect resources
Before EachReset state
After EachClean up
After AllDisconnect

6. Mocking Principles

When to Mock

MockDon't Mock
External APIsThe code under test
Database (unit)Simple dependencies
Time/randomPure functions
NetworkIn-memory stores

Mock Types

TypeUse
StubReturn fixed values
SpyTrack calls
MockSet expectations
FakeSimplified implementation

7. Test Organization

Naming

PatternExample
Should behavior"should return error when..."
When condition"when user not found..."
Given-when-then"given X, when Y, then Z"

Grouping

LevelUse
describeGroup related tests
it/testIndividual case
beforeEachCommon setup

8. Test Data

Strategies

ApproachUse
FactoriesGenerate test data
FixturesPredefined datasets
BuildersFluent object creation

Principles

  • Use realistic data
  • Randomize non-essential values (faker)
  • Share common fixtures
  • Keep data minimal

9. Best Practices

PracticeWhy
One assert per testClear failure reason
Independent testsNo order dependency
Fast testsRun frequently
Descriptive namesSelf-documenting
Clean upAvoid side effects

10. Anti-Patterns

❌ Don't✅ Do
Test implementationTest behavior
Duplicate test codeUse factories
Complex test setupSimplify or split
Ignore flaky testsFix root cause
Skip cleanupReset state

Remember: Tests are documentation. If someone can't understand what the code does from the tests, rewrite them.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

2D game development principles. Sprites, tilemaps, physics, camera.

The English summary is being prepared. Showing the original description.

umairinayat/Specter-AI19Updated Sep 29, 2026

3D game development principles. Rendering, shaders, physics, cameras.

The English summary is being prepared. Showing the original description.

umairinayat/Specter-AI19Updated Sep 29, 2026

API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.

The English summary is being prepared. Showing the original description.

umairinayat/Specter-AI19Updated Sep 29, 2026

Main application building orchestrator. Creates full-stack applications from natural language requests. Determines project type, selects tech stack, coordinates agents.

The English summary is being prepared. Showing the original description.

umairinayat/Specter-AI19Updated Sep 29, 2026

Architectural decision-making framework. Requirements analysis, trade-off evaluation, ADR documentation. Use when making architecture decisions or analyzing system design.

The English summary is being prepared. Showing the original description.

umairinayat/Specter-AI19Updated Sep 29, 2026

Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.

The English summary is being prepared. Showing the original description.

umairinayat/Specter-AI19Updated Sep 29, 2026

See all skills by umairinayat

Report a problem with this skill