Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use this skill when writing or improving tests of any kind — unit tests, integration tests, end-to-end (E2E) tests, API tests, or test coverage analysis. Trigger on keywords: test, spec, unit test, integration test, E2E, Playwright, Jest, Vitest, pytest, mock, coverage, TDD, test suite, assertion.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-11 | ✗→✓ | ▲ Improved | 50% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 5% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 12% | 0% |
| case-02 | ✓→✓ | = Same ✓ | -6% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 148% | 0% |
AI-generated code is untrusted until it passes a human-reviewed test suite. Tests are not optional — they are the safety net that makes refactoring and agentic code generation safe. Treat test code with the same quality standards as production code.
The Verify Output Principle: Every piece of AI-generated code should pass through an AI-generated but human-reviewed test suite before being considered complete.
text/\ /E2E\ ← Few, slow, high confidence /------\ /Integr. \ ← Some, medium speed /------------\ / Unit Tests \ ← Many, fast, isolated /------------------\
describe('ComponentOrFunction', () => {
describe('methodName', () => {
it('should [expected behavior] when [condition]', () => {
// Arrange
const input = ...
// Act
const result = functionUnderTest(input)
// Assert
expect(result).toBe(expectedValue)
})
})
})| Scenario | Priority | |---|---| | Happy path (expected behavior) | Must have | | Edge cases (null, empty, boundary) | Must have | | Error paths (exceptions, failures) | Must have | | Invalid inputs | Must have | | Performance-critical paths | Nice to have |
python# Python example def test_create_user_persists_to_db(db_session): # Arrange user_data = {"name": "James", "email": "james@test.com"} # Act user = create_user(db_session, user_data) # Assert saved = db_session.query(User).filter_by(id=user.id).first() assert saved.email == "james@test.com"
Use Playwright for E2E testing — it supports all major browsers, has auto-wait built in, and works well with AI agent verification.
getByRole() — ARIA roles (most resilient)getByText() — visible textgetByTestId() — data-testid attributesgetByLabel() — form labelstypescripttest('user can complete checkout flow', async ({ page }) => { // Navigate await page.goto('/products') // Interact await page.getByRole('button', { name: 'Add to Cart' }).first().click() await page.getByRole('link', { name: 'Checkout' }).click() // Fill form await page.getByLabel('Email').fill('test@example.com') // Assert await expect(page.getByText('Order confirmed')).toBeVisible() })
| Type | When to Use | |---|---| | Mock | Verify a function was called with specific arguments | | Stub | Replace a function with a fixed return value | | Spy | Observe calls without replacing behavior | | Fake | Lightweight working implementation (e.g., in-memory DB) |
Always mock external API calls in unit/integration tests:
typescriptjest.mock('../services/paymentService', () => ({ chargeCard: jest.fn().mockResolvedValue({ success: true }) }))
| Coverage Level | Meaning | |---|---| | < 60% | Dangerous — high risk of regressions | | 60–80% | Acceptable for early-stage projects | | 80–90% | Good — production ready | | 90–95% | Excellent | | > 95% | Diminishing returns — focus on quality not quantity |
Coverage doesn't equal quality. 95% coverage with weak assertions is worse than 80% coverage with strong assertions.
| Language | Unit | Integration | E2E | |---|---|---|---| | TypeScript/JS | Jest / Vitest | Supertest + Jest | Playwright | | Python | pytest | pytest + SQLAlchemy | Playwright | | Java | JUnit 5 | Spring Boot Test | Playwright |
Other measured skills in the registry, with their headline benchmark lift.