$
copilot --idea "Test Suite Generator"
→
Go from 0% to 80% code coverage in an afternoon with AI-generated tests
The Problem
The codebase has 12% test coverage. Every PR review includes the comment "we should add tests for this." Nobody does. The CI pipeline has a coverage gate that's been disabled since 2023 because it was "too noisy."
What You'll Build
A systematic testing workflow that takes an untested codebase and produces:
- Unit tests for all public functions with meaningful assertions
- Edge case tests (nulls, empty inputs, boundaries, concurrency)
- Integration tests for API endpoints
- A coverage report showing the improvement
Step-by-Step Walkthrough
Phase 1: Coverage Analysis
$
"Analyse this codebase for test coverage.
Which files have zero tests?
Which functions are called the most but tested the least?
Prioritise by risk: what breaks worst if it has a bug?"
Phase 2: Generate Unit Tests (Batch by Module)
Work through one module at a time:
$
"Generate unit tests for every public function in src/services/user-service.
Use Jest with descriptive test names.
Include:
- Happy path with valid inputs
- Invalid inputs (null, undefined, empty string, wrong type)
- Boundary values (0, -1, MAX_INT, empty array, single element)
- Error cases (throw on database failure, return null on not found)
Mock external dependencies with jest.mock()."
Run the tests after each batch:
$
"Run the tests we just created and fix any failures."
The task agent is perfect here — it only shows output when tests fail.
Phase 3: Integration Tests
$
"Create integration tests for the API endpoints in routes/users.js.
Use supertest with an in-memory database.
Test:
- All CRUD operations return correct status codes
- Validation errors return 400 with descriptive messages
- Authentication required endpoints return 401 without a token
- Pagination, filtering, and sorting work correctly
- Concurrent requests don't cause race conditions"
Phase 4: Edge Cases & Security Tests
$
"Add security-focused test cases:
- SQL injection attempts in all text inputs
- XSS payloads in user-submitted content
- Oversized request bodies (>10MB)
- Missing Content-Type headers
- Invalid JWT tokens (expired, malformed, wrong audience)
- Rate limiting enforcement"
Phase 5: Coverage Report & CI Integration
$
"Run the full test suite with coverage reporting.
Show coverage by file.
Update the CI pipeline to:
- Run tests on every PR
- Enforce 70% coverage minimum for new code
- Post a coverage diff comment on the PR"
Pro Tips
• Generate tests FIRST (TDD style), then fix the code if tests reveal bugs
• Use the task agent to run tests — it keeps your context clean
• Don't aim for 100% — focus on testing behaviour, not implementation
• Ask Copilot to review existing tests too: "Are any of these tests testing nothing useful?"
What You'll Learn
• Testing patterns: unit, integration, and edge case coverage
• Mocking strategies for external dependencies
• TDD workflows with AI pair programming
• CI/CD integration for test enforcement