Testing

From aiskillstore/marketplace · View interactive version

Testing is an AI agent skill from the GitHub repository aiskillstore/marketplace. Comprehensive testing specialization covering test strategy, automation, TDD methodology, test writing, and web app testing. Use when setting up test infrastructure, writing tests, implementing TDD workflows, analyzing coverage, integrating tests into CI/CD, or testing web applications with Playwrig

How to use this skill

Skill file

Testing

This skill provides comprehensive testing capabilities including test strategy, automation setup, Test-Driven Development (TDD), test writing best practices, coverage analysis, CI/CD integration, and web application testing with Playwright.

When to Use This Skill

What This Skill Does

  1. Test Strategy: Designs comprehensive testing strategies (unit, integration, E2E)
  2. Test Automation: Sets up test frameworks and automation tools
  3. TDD Methodology: Implements Test-Driven Development workflows (Red-Green-Refactor)
  4. Test Writing: Writes focused, maintainable tests with proper patterns
  5. Coverage Analysis: Analyzes and improves test coverage
  6. CI/CD Integration: Integrates tests into continuous integration pipelines
  7. Web App Testing: Tests web applications using Playwright
  8. Test Quality: Improves test reliability and maintainability

Test Strategy

Test Pyramid

Recommended Distribution:

Test Types:

Framework Selection

JavaScript/TypeScript:

Python:

Java:

Go:

Rust:

Test-Driven Development (TDD)

TDD is a design technique, not just a testing technique. It produces better-designed, more maintainable code through small, disciplined steps.

Core Principle

Write tests before code. Always. TDD forces you to think about:

The Three Laws (Never Violate)

  1. Write NO production code without a failing test first
  2. Write only enough test to demonstrate one failure
  3. Write only enough code to pass that test

Red-Green-Refactor Cycle

Phase 1: RED - Write Failing Test

  1. Write ONE test that defines desired behavior
  2. Run test - verify it FAILS
  3. Verify it fails for the RIGHT reason (not syntax error)
  4. DO NOT write implementation yet

Phase 2: GREEN - Minimal Implementation

  1. Write MINIMAL code to make test pass
  2. Resist urge to add extra features
  3. Run test - verify it PASSES
  4. If test still fails, fix implementation (not test)

Phase 3: REFACTOR - Clean Code

  1. Remove code duplication (DRY)
  2. Improve naming for clarity
  3. Extract complex logic into functions
  4. Run ALL tests - must stay green throughout
  5. Check test coverage on changed lines

After REFACTOR, start new RED phase for next behavior.

Test Writing Patterns

Arrange-Act-Assert (AAA)

Structure:

  1. Arrange: Set up test data and conditions
  2. Act: Execute the code being tested
  3. Assert: Verify the expected outcome

Example:

describe('UserService', () => {
  it('should create user with valid data', async () => {
    // Arrange
    const userData = { email: 'test@example.com', name: 'Test User' };

    // Act
    const result = await userService.createUser(userData);

    // Assert
    expect(result).toHaveProperty('id');
    expect(result.email).toBe(userData.email);
  });
});

Given-When-Then (BDD Style)

Structure:

  1. Given: Initial context/preconditions
  2. When: Action/event that triggers behavior
  3. Then: Expected outcome

Test Organization

File Structure:

project/
├── src/
│   └── components/
│       └── User.jsx
├── tests/
│   ├── unit/
│   │   └── User.test.jsx
│   ├── integration/
│   │   └── UserAPI.test.js
│   └── e2e/
│       └── user-flow.spec.js
├── jest.config.js
└── playwright.config.js

Coverage Analysis

Coverage Goals

Recommended Thresholds:

Critical Paths:

Coverage Gaps

Common Gaps:

Improvement Strategies:

CI/CD Integration

Test Pipeline

Stages:

  1. Unit Tests: Fast feedback, run on every commit
  2. Integration Tests: Run on pull requests
  3. E2E Tests: Run before merging to main
  4. Performance Tests: Run on main branch

Quality Gates:

Web Application Testing with Playwright

Helper Scripts

This skill includes Python helper scripts in scripts/:

```bash

# Single server

python scripts/with_server.py --server "npm run dev" --port 5173 -- python your_automation.py

# Multiple servers (e.g., backend + frontend)

python scripts/with_server.py \

--server "cd backend && python server.py" --port 3000 \

--server "cd frontend && npm run dev" --port 5173 \

-- python your_automation.py

```

Decision Tree: Choosing Your Approach

User task → Is it static HTML?
    ├─ Yes → Read HTML file directly to identify selectors
    │         ├─ Success → Write Playwright script using selectors
    │         └─ Fails/Incomplete → Treat as dynamic (below)
    │
    └─ No (dynamic webapp) → Is the server already running?
        ├─ No → Run: python scripts/with_server.py --help
        │        Then use the helper + write simplified Playwright script
        │
        └─ Yes → Reconnaissance-then-action:
            1. Navigate and wait for networkidle
            2. Take screenshot or inspect DOM
            3. Identify selectors from rendered state
            4. Execute actions with discovered selectors

Playwright Best Practices

Example: Basic Playwright Script

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()
    page.goto('http://localhost:5173')
    page.wait_for_load_state('networkidle')  # CRITICAL: Wait for JS to execute
    # ... your automation logic
    browser.close()

Examples

See examples/ directory for:

Reference Files

For detailed testing patterns and workflows, load reference files as needed:

When working with specific frameworks or need detailed patterns, load the appropriate reference file.

Best Practices

Test Quality

  1. Isolation: Tests should be independent and runnable in any order
  2. Deterministic: Tests should produce consistent results
  3. Fast: Unit tests should run quickly (< 100ms each)
  4. Clear: Test names should describe what they test
  5. Maintainable: Tests should be easy to update when code changes

TDD Best Practices

  1. One Behavior Per Test: Each test verifies ONE behavior
  2. Descriptive Names: Test names describe the behavior being tested
  3. Independent Tests: Tests don't depend on each other
  4. Fast Tests: Mock external dependencies to keep tests fast
  5. Clear Assertions: Assertions clearly show what's being verified

Common Mistakes to Avoid

Test Maintenance

Integration with Other Skills

Meta-Principle

TDD is a DESIGN technique, not a testing technique.

The cycle never changes: RED → GREEN → REFACTOR → Repeat

Writing tests first forces you to think about:
- What behavior do I need?
- How will I know it works?
- What's the simplest implementation?

This produces better-designed, more maintainable code.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.