home / skills / htooayelwinict / claude-config / testing

testing skill

/skills/testing

This skill helps you design and maintain tests across PHP, Python, and JS using TDD with Pest, pytest, Vitest, and Playwright.

npx playbooks add skill htooayelwinict/claude-config --skill testing

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
3.6 KB
---
name: testing
description: |
  Write and manage tests using TDD with Pest (PHP), Vitest (React), pytest (Python), and Playwright (E2E). Use when writing
  feature tests, unit tests, component tests, visual regression tests, or improving test coverage. EXCLUSIVE to testing-expert agent.
allowed-tools: Read, Edit, Bash, Grep, Glob, Write, mcp_gemini-bridge, mcp_open-bridge, mcp_codex-bridge, mcp_context7, mcp_playwright, mcp_zai-mcp-server
---
# Testing

**Exclusive to:** `testing-expert` agent

## MCP Helpers (Brain + Memory)

### 🧠 Gemini-Bridge (Brain) — Test Strategy Advice
```
mcp_gemini-bridge_consult_gemini(query="Suggest comprehensive test cases for: [feature]. Include edge cases.", directory=".")
```

### 🌉 Open-Bridge — Alternative Test Strategy
```
mcp_open-bridge_consult_gemini(query="Suggest comprehensive test cases for: [feature]. Include edge cases.", directory=".")
```

### 📚 Context7 (Memory) — Up-to-Date Docs

Lookup testing patterns and assertions:
```
mcp_context7_resolve-library-id(libraryName="pytest", query="fixtures async")
mcp_context7_query-docs(libraryId="/pytest-dev/pytest", query="parametrize examples")
```

## 🖼️ Visual Testing (Web Apps)

For UI/UX testing, use Playwright MCP to capture and Vision AI to analyze:

### Capture Screenshots
```
mcp_playwright_browser_navigate(url="http://localhost:8000/[page]")
mcp_playwright_browser_take_screenshot(filename="test-screenshot.png")
```

### Analyze with Vision AI
```
mcp_zai-mcp-server_analyze_image(
  image_path="test-screenshot.png",
  prompt="Analyze this UI: check layout, colors, spacing, alignment, accessibility issues"
)
```

### Visual Regression Flow
1. Capture baseline screenshot
2. Make changes
3. Capture new screenshot
4. Use Vision AI to compare and validate

## Validation Loop (MANDATORY)

After writing or modifying tests, always verify:
```bash
composer test           # PHP tests pass
npm run test           # JS tests pass (if applicable)
```

**TDD Feedback Loop:**
1. Write test → Verify it FAILS (Red)
2. Implement minimal code → Verify it PASSES (Green)
3. Refactor → Verify it still PASSES
4. Repeat for edge cases

## Instructions (TDD Workflow)

| Step | Action | Verification |
|------|--------|--------------|
| 1 | Write failing test | `composer test --filter=NewTest` → FAILS |
| 2 | Implement minimal code | `composer test --filter=NewTest` → PASSES |
| 3 | Refactor | `composer test` → ALL PASS |
| 4 | Add edge cases | Repeat steps 1-3 |

## Pest Patterns (Laravel)

### Feature Test
```php
test('user can create post', function () {
    $user = User::factory()->create();
    
    $this->actingAs($user)
        ->post('/posts', ['title' => 'Test'])
        ->assertRedirect('/posts');
        
    $this->assertDatabaseHas('posts', ['title' => 'Test']);
});
```

### Unit Test
```php
test('generates slug from title', function () {
    expect((new SlugGenerator)->generate('Hello World'))
        ->toBe('hello-world');
});
```

## Vitest Patterns (React)

```tsx
describe('PostForm', () => {
    it('submits with valid data', async () => {
        const onSubmit = vi.fn();
        render(<PostForm onSubmit={onSubmit} />);
        
        await userEvent.type(screen.getByLabelText(/title/i), 'Test');
        await userEvent.click(screen.getByRole('button', { name: /submit/i }));
        
        expect(onSubmit).toHaveBeenCalled();
    });
});
```

## Test Commands

```bash
# Laravel
composer test
php artisan test --filter=PostTest
php artisan test --coverage

# React
npm run test
npm run test:watch
npm run test:coverage
```

## Examples
- "Write tests for PostController"
- "Add unit tests for this service"
- "Fix failing test"

Overview

This skill helps you write and manage tests using TDD with Pest (PHP), Vitest (React), pytest (Python), and Playwright (E2E). It focuses on feature tests, unit tests, component tests, visual regression, and improving test coverage. Use this skill when you want disciplined test-driven workflows and reliable test suites.

How this skill works

I guide you through a TDD feedback loop: write a failing test, implement the minimal change to pass, then refactor while keeping tests green. I provide concrete test patterns for Pest, Vitest, and pytest, and orchestrate visual testing with Playwright screenshots plus Vision AI analysis. After changes I always recommend running the validation commands to confirm suite status and coverage.

When to use it

  • When adding new features and you want tests-first development
  • When increasing or validating test coverage for critical modules
  • When writing unit, integration, or component tests for backend or frontend
  • When setting up visual regression tests for UI changes using Playwright
  • When debugging or fixing flaky or failing tests

Best practices

  • Follow the TDD loop: Red → Green → Refactor for every behavior
  • Keep tests small and focused: one assertion per behavior where practical
  • Use factories/fixtures and dependency injection to minimize brittle tests
  • Record baseline screenshots for UI tests and compare after changes
  • Run the full validation commands after changes (composer test, npm run test, pytest)

Example use cases

  • Write feature tests for a Laravel PostController with Pest and database assertions
  • Add unit tests for a Python service using pytest and parametrized edge cases
  • Implement component tests for a React form using Vitest and user-event to simulate interactions
  • Create Playwright visual regression: capture baseline, change UI, capture new screenshot, analyze differences with Vision AI
  • Fix a failing test by reproducing failure, applying minimal fix, then running full test/coverage commands

FAQ

Which command should I run after writing or changing tests?

Run your language-specific test runner: composer test for PHP, npm run test for JS, pytest for Python. Also run coverage commands when needed.

How do I validate visual changes in the UI?

Capture a baseline screenshot with Playwright, make the UI changes, capture a new screenshot, then compare and analyze with Vision AI to detect layout, spacing, color, and accessibility regressions.