Agent skill

testing-strategy

Testing strategies and best practices for unit, integration, and end-to-end tests. Use when setting up test infrastructure, writing test cases, or deciding what to test. Covers test pyramid, mocking strategies, and coverage guidelines.

Stars 2
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/adilkalam/orca/tree/main/skills/testing-strategy

SKILL.md

Testing Strategy

Test Pyramid

        /\
       /  \      E2E Tests (few)
      /----\     - Critical user flows
     /      \    - Smoke tests
    /--------\   
   /          \  Integration Tests (some)
  /------------\ - API contracts
 /              \- Database queries
/----------------\
     Unit Tests (many)
     - Pure functions
     - Business logic
     - Edge cases

Unit Testing Principles

What to Test

  • Pure functions with business logic
  • Edge cases and boundary conditions
  • Error handling paths
  • State transitions

What NOT to Unit Test

  • Framework code
  • Third-party libraries
  • Simple getters/setters
  • Trivial code

AAA Pattern

typescript
test('calculates total with discount', () => {
  // Arrange
  const items = [{ price: 100 }, { price: 50 }];
  const discount = 0.1;
  
  // Act
  const total = calculateTotal(items, discount);
  
  // Assert
  expect(total).toBe(135);
});

Mocking Strategies

When to Mock

  • External services (APIs, databases)
  • Time-dependent code
  • Random values
  • Side effects (file system, network)

When NOT to Mock

  • The code under test
  • Simple value objects
  • Internal implementation details

Mock Examples

typescript
// Jest mock
jest.mock('./api', () => ({
  fetchUser: jest.fn().mockResolvedValue({ id: 1, name: 'Test' })
}));

// Spy on method
const spy = jest.spyOn(service, 'save');
expect(spy).toHaveBeenCalledWith(expectedData);

// Mock timer
jest.useFakeTimers();
jest.advanceTimersByTime(1000);

Integration Testing

API Testing

typescript
describe('POST /users', () => {
  it('creates user with valid data', async () => {
    const response = await request(app)
      .post('/users')
      .send({ name: 'Test', email: 'test@example.com' })
      .expect(201);
    
    expect(response.body).toMatchObject({
      id: expect.any(Number),
      name: 'Test'
    });
  });
});

Database Testing

  • Use test database or in-memory
  • Reset state between tests
  • Use transactions for isolation

E2E Testing

What to Cover

  • Critical user journeys
  • Authentication flows
  • Payment/checkout flows
  • Error states users might see

Best Practices

  • Use data-testid attributes
  • Wait for elements properly
  • Test in isolation when possible
  • Keep tests deterministic
typescript
// Playwright example
test('user can complete checkout', async ({ page }) => {
  await page.goto('/products');
  await page.click('[data-testid="add-to-cart"]');
  await page.click('[data-testid="checkout"]');
  await page.fill('[data-testid="email"]', 'test@example.com');
  await page.click('[data-testid="submit"]');
  await expect(page.locator('[data-testid="success"]')).toBeVisible();
});

Coverage Guidelines

  • Aim for 80% coverage as baseline
  • 100% coverage != bug-free code
  • Focus on critical paths, not metrics
  • Exclude generated code, config files

Expand your agent's capabilities with these related and highly-rated skills.

adilkalam/orca

web-interface-guidelines

Web UI quality rules: interactions, forms, loading, animations, layout, content, performance, accessibility, design. Apply to all web UI work. Adapted from Vercel Design Guidelines.

2 0
Explore
adilkalam/orca

react-performance

React/Next.js performance patterns with wrong/right code examples. Apply when building or reviewing React components. Adapted from Vercel React Best Practices by @shuding.

2 0
Explore
adilkalam/orca

stripe-integration

Payment integration patterns for Stripe. Covers checkout sessions, subscriptions, webhooks, idempotency, and the sharp edges that cause real-money bugs. Backend-agnostic with examples for Next.js App Router and Django REST Framework.

2 0
Explore
adilkalam/orca

frontend-aesthetics

Global frontend aesthetics skill that helps Claude avoid generic "AI slop" UI and make bold, intentional visual decisions while still honoring each project's design-dna, tokens, and architecture.

2 0
Explore
adilkalam/orca

pg-style-editor

Edit writing to adopt Paul Graham's exceptionally clear style for research and long-form content - concrete language, varied sentence rhythm, accessible formality, specific evidence. Use when user wants to rewrite content in PG's style or asks to "make this clearer" or "simplify research writing."

2 0
Explore
adilkalam/orca

lovable-pitfalls

Catalog of critical mistakes to avoid: re-reading context files, writing without reading, sequential tool calls, premature coding, overengineering, scope creep, and monolithic files.

2 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results