Skip to content
local-service-testing logo

Local Service Testing

local-service-testing

Use when code changes touch database, cache, queue, or other service-dependent components - enforces testing against real local services instead of mocks

SKILL.md

Full skill instructions

Local Service Testing

Overview

Test against real services locally before pushing. CI validates—it doesn't discover.

Core principle: If you mock what you can run locally, you're hiding bugs.

Announce at start: "I'm using local-service-testing to verify changes against real services."

The Iron Law

CI DISCOVERS NOTHING.
IF CI FINDS A BUG, YOUR LOCAL TESTING FAILED.

Local services exist for a reason. Use them.

Critical Clarification

Unit tests with mocks: REQUIRED (for TDD cycle) Integration tests with real services: ALSO REQUIRED

This skill does NOT replace mocking in unit tests. It ADDS the requirement for integration tests against real services. Both are mandatory.

When This Skill Applies

Code ChangeRequired ServiceMust Test Against
Database models/​entitiespostgresReal postgres
MigrationspostgresReal postgres
Repository/​ORM layerpostgresReal postgres
SQL queriespostgresReal postgres
Cache operationsredisReal redis
Session storageredisReal redis
Pub/​sub messagesredis/​rabbitmqReal queue
Queue workersredis/​rabbitmqReal queue
API endpointsall servicesAll running

If your change touches any of these, you MUST test against the real service.

Service Detection

At session start, the session-start.sh hook reports available services:

Checking development services...
  ✓ Found docker-compose.yml

  Available services:
    ✓ postgres (running)
    ○ redis (not running)

  Tip: Start services with: docker-compose up -d

Starting Services

# Start all services
docker-compose up -d

# Start specific service
docker-compose up -d postgres

# Check status
docker-compose ps

Service Connection Strings

ServiceDefault Connection
postgrespostgresql://localhost:5432/​dev
redisredis://localhost:6379
rabbitmqamqp://localhost:5672

Check your project's .env.example or docker-compose.yml for actual values.

Testing Protocol

Step 1: Identify Service Dependencies

Before testing, identify which services your changes require:

# Check what files you've changed
git diff --name-only HEAD~1

# Map to services:
# *.sql, *migration*, *model*, *entity*, *repository* → postgres
# *cache*, *redis*, *session*, *queue*, *pub*, *sub* → redis
# *worker*, *job*, *consumer* → queue service

Step 2: Ensure Services Running

# Start required services
docker-compose up -d postgres redis

# Verify they're ready
docker-compose ps

# Test connectivity
# Postgres
psql postgresql://localhost:5432/​dev -c "SELECT 1"

# Redis
redis-cli ping

Step 3: Run Integration Tests

# Run integration tests (not unit tests with mocks)
pnpm test:integration

# Or run specific integration test suite
pnpm test --grep "integration"

# For Python projects
pytest tests/​integration/

# For Go projects
go test -tags=integration ./​...

Step 4: Verify Locally Before Pushing

Before git push:

# Full verification
pnpm build
pnpm lint
pnpm typecheck
pnpm test              # Unit tests
pnpm test:integration  # Integration tests against real services

Two-Layer Testing Requirement

Both Are Required

Test LayerPurposeUses Mocks?Uses Real Services?Required?
Unit testsTDD cycle, verify logicYESNoYES
Integration testsVerify real behaviorNoYESYES

Why Both?

  • Unit tests with mocks: Fast, enable RED-GREEN-REFACTOR, isolate logic
  • Integration tests with services: Catch real-world failures mocks miss

We've experienced 80% failure rates with ORM migrations because unit tests with mocks passed but real databases rejected the changes.

What Mocks Miss

// Mock says this works
const mockDb = {
  query: jest.fn().mockResolvedValue([{ id: 1 }])
};

// But real postgres throws:
// ERROR: relation "users" does not exist
// ERROR: column "email" cannot be null
// ERROR: duplicate key violates unique constraint

Real services reveal:

  • Schema mismatches
  • Constraint violations
  • Connection issues
  • Transaction behavior
  • Performance problems

Artifact Requirement

Before creating a PR, you must post local testing evidence to the issue.

Required Artifact Format

<!-- LOCAL-TESTING:START -->
## Local Service Testing

| Service | Status | Verification |
|---------|--------|--------------|
| postgres | ✅ Running | Migrations applied, queries executed |
| redis | ✅ Running | Cache operations verified |

**Tests Run:**
- `pnpm test:integration` - PASSED
- Manual verification of [specific feature]

**Tested At:** 2025-01-15T10:30:00Z
<!-- LOCAL-TESTING:END -->

Where to Post

Post as a comment on the GitHub issue you're working on. This is checked by the validate-local-testing.sh PreToolUse hook before PR creation.

When Artifact is Required

The hook checks:

  1. Does docker-compose.yml exist?
  2. Do changed files match service patterns?
  3. If yes to both → artifact required

If no services are relevant to your changes, no artifact is needed.

Common Patterns

Database Testing

// GOOD: Test against real postgres
describe('UserRepository (integration)', () => {
  beforeAll(async () => {
    await db.migrate.latest();
  });

  afterAll(async () => {
    await db.destroy();
  });

  it('creates user with unique email constraint', async () => {
    await userRepo.create({ email: '[email protected]' });

    // Real postgres will throw on duplicate
    await expect(
      userRepo.create({ email: '[email protected]' })
    ).rejects.toThrow(/​unique constraint/);
  });
});

Cache Testing

// GOOD: Test against real redis
describe('CacheService (integration)', () => {
  beforeEach(async () => {
    await redis.flushdb();
  });

  it('expires keys after TTL', async () => {
    await cache.set('key', 'value', { ttl: 1 });

    expect(await cache.get('key')).toBe('value');

    await sleep(1100);

    expect(await cache.get('key')).toBeNull();
  });
});

API Testing

// GOOD: Test against real services
describe('POST /​users (integration)', () => {
  it('creates user and caches result', async () => {
    const response = await request(app)
      .post('/​users')
      .send({ email: '[email protected]' });

    expect(response.status).toBe(201);

    // Verify in real database
    const user = await db('users').where({ email: '[email protected]' }).first();
    expect(user).toBeDefined();

    // Verify in real cache
    const cached = await redis.get(`user:${user.id}`);
    expect(cached).toBeDefined();
  });
});

Troubleshooting

ProblemSolution
Service not startingCheck docker-compose logs [service]
Connection refusedEnsure service is running and port is correct
Database doesn't existRun migrations: pnpm migrate
Tests pass locally, fail in CIEnvironment variable mismatch—check .env vs CI config
Flaky integration testsCheck for proper test isolation and cleanup

Checklist

Before creating PR:

  • Identified all service dependencies for changes
  • All required services are running locally
  • Integration tests pass against real services
  • Posted local testing artifact to issue
  • Did not rely on mocks for service-dependent code

Integration

This skill is called by:

  • tdd-full-coverage - For integration testing requirements
  • issue-driven-development - Before PR creation
  • verification-before-merge - As a merge gate

This skill is enforced by:

  • validate-local-testing.sh - PreToolUse hook blocks PR without artifact

This skill references:

  • environment-bootstrap - For service startup patterns
  • session-start - For service detection at session start

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View