Skip to main content
ClaudeWave
Skill145 repo starsupdated yesterday

GitHub Copilot Testing Patterns

Effective patterns for using GitHub Copilot to generate, refactor, and maintain test code including prompt engineering for test generation, Copilot Chat for debugging, inline suggestions for assertions, and workspace context optimization.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/PramodDutta/qaskills /tmp/github-copilot-testing-patterns && cp -r /tmp/github-copilot-testing-patterns/seed-skills/copilot-testing-patterns ~/.claude/skills/github-copilot-testing-patterns
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# GitHub Copilot Testing Patterns Skill

You are an expert in leveraging GitHub Copilot for test automation. When the user asks you to generate tests with Copilot, optimize Copilot suggestions for testing, use Copilot Chat for test debugging, or configure Copilot for testing workflows, follow these detailed instructions.

## Core Principles

1. **Context is king** -- Copilot generates better tests when it has access to the source code, existing test patterns, and project conventions. Keep relevant files open and organized.
2. **Comment-driven generation** -- Write descriptive comments before test functions to guide Copilot's suggestions. The comment becomes the specification.
3. **Pattern establishment** -- Write 2-3 example tests manually, then let Copilot follow the pattern. It excels at pattern continuation.
4. **Iterative refinement** -- Accept Copilot's initial suggestion, then refine. It is faster to edit a 80% correct suggestion than to write from scratch.
5. **Chat for complex scenarios** -- Use Copilot Chat for multi-step test generation, test refactoring, and debugging failed tests.
6. **Workspace awareness** -- Copilot uses open files as context. Keep the source file and existing test file open when generating new tests.
7. **Review everything** -- Copilot generates plausible but potentially incorrect tests. Every suggestion must be reviewed for correctness, completeness, and style.

## Project Structure

```
src/
  services/
    user-service.ts
    user-service.test.ts    # Keep test next to source
  utils/
    validators.ts
    validators.test.ts
  components/
    Button/
      Button.tsx
      Button.test.tsx
.github/
  copilot/
    instructions.md         # Custom instructions for Copilot
    test-patterns.md        # Test pattern examples
.vscode/
  settings.json             # Copilot configuration
```

## Copilot Custom Instructions for Testing

```markdown
<!-- .github/copilot/instructions.md -->
# Test Generation Instructions

When generating tests, follow these conventions:
- Use vitest with TypeScript
- Follow Arrange-Act-Assert (AAA) pattern
- Name tests: "should [expected behavior] when [condition]"
- Group tests in describe blocks by function name
- Mock external dependencies using vi.mock()
- Include edge cases: null, undefined, empty values, boundaries
- Include error cases for every function that can throw
- Use strict TypeScript types (no `any`)
- Add meaningful assertion messages
```

## Comment-Driven Test Generation Patterns

```typescript
// Pattern 1: Descriptive comment before test
// Copilot will generate the test body based on the comment

// Test that validateEmail returns true for valid emails
// and false for invalid emails including empty strings,
// missing @ symbol, and missing domain
import { describe, it, expect } from 'vitest';
import { validateEmail } from './validators';

describe('validateEmail', () => {
  // should return true for standard email format
  it('should return true for standard email format', () => {
    expect(validateEmail('user@example.com')).toBe(true);
  });

  // should return true for email with subdomain
  it('should return true for email with subdomain', () => {
    expect(validateEmail('user@mail.example.com')).toBe(true);
  });

  // should return false for empty string
  it('should return false for empty string', () => {
    expect(validateEmail('')).toBe(false);
  });

  // should return false for email without @ symbol
  it('should return false for email without @ symbol', () => {
    expect(validateEmail('userexample.com')).toBe(false);
  });

  // should return false for email without domain
  it('should return false for email without domain', () => {
    expect(validateEmail('user@')).toBe(false);
  });

  // Copilot will continue the pattern with more edge cases...
});
```

## Pattern 2: Type-Driven Generation

```typescript
// When the source code has strong types, Copilot infers test cases from types

// Source: user-service.ts
interface CreateUserInput {
  name: string;       // 1-100 characters
  email: string;      // valid email format
  age: number;        // 18-150
  role: 'admin' | 'user' | 'editor';
}

interface UserService {
  createUser(input: CreateUserInput): Promise<User>;
  findById(id: string): Promise<User | null>;
  updateUser(id: string, updates: Partial<CreateUserInput>): Promise<User>;
  deleteUser(id: string): Promise<void>;
}

// Test file: user-service.test.ts
// Copilot uses the types to generate comprehensive tests
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { UserService } from './user-service';

describe('UserService', () => {
  let service: UserService;

  beforeEach(() => {
    service = new UserService(/* mocked deps */);
  });

  describe('createUser', () => {
    // Valid creation with all required fields
    it('should create user with valid input', async () => {
      const input = { name: 'John Doe', email: 'john@test.com', age: 25, role: 'user' as const };
      const user = await service.createUser(input);
      expect(user.name).toBe('John Doe');
      expect(user.email).toBe('john@test.com');
    });

    // Copilot generates boundary tests based on type comments
    // Name boundary: empty name
    it('should reject empty name', async () => {
      const input = { name: '', email: 'john@test.com', age: 25, role: 'user' as const };
      await expect(service.createUser(input)).rejects.toThrow();
    });

    // Name boundary: name exceeding 100 characters
    it('should reject name over 100 characters', async () => {
      const input = { name: 'a'.repeat(101), email: 'john@test.com', age: 25, role: 'user' as const };
      await expect(service.createUser(input)).rejects.toThrow();
    });

    // Age boundary: below minimum (18)
    it('should reject age below 18', async () => {
      const input = { name: 'John', email: 'john@test.com', age: 17, role: 'user' as const };
      await expect(service.createUser(input)).rejects.toThrow();
    });
axe-core Accessibility AutomationSkill

Automated accessibility testing with axe-core integrated into CI pipelines, including custom rule configuration, issue prioritization, and remediation guidance.

A/B Test ValidationSkill

Validating A/B test implementations including traffic splitting accuracy, statistical significance calculation, metric tracking, and experiment cleanup.

Accessibility A11y EnhancedSkill

Comprehensive WCAG compliance and accessibility testing covering ARIA, keyboard navigation, screen readers, color contrast, and automated a11y validation.

Accessibility AuditorSkill

Comprehensive WCAG 2.1 AA compliance testing combining automated axe-core scans with manual keyboard navigation, screen reader compatibility, and focus management verification

AFL++ Fuzzing TestingSkill

American Fuzzy Lop Plus Plus mutation-based fuzz testing for finding crashes, hangs, and security vulnerabilities in binary programs.

Agent Browser AutomationSkill

Fast Rust-based headless browser automation CLI with Node.js fallback for AI agents, featuring navigation, clicking, typing, snapshots, and structured commands optimized for agent workflows.

Agentic Testing PatternsSkill

AI-first testing methodology where autonomous agents plan, generate, execute, and maintain test suites with minimal human intervention, covering agent orchestration, feedback loops, and intelligent test prioritization.

AI Agent EvaluationSkill

Comprehensive evaluation patterns for AI agents including multi-turn conversation testing, LLM-as-judge frameworks, benchmark suites, regression detection, and systematic eval pipelines for measuring agent quality and safety.