testing-best-practices

Guides Laravel and Pest test design, coverage selection, and test review.

Updated Aug 31, 2026
One-click install
npx skills add https://github.com/coleYab/usacr --skill testing-best-practices-coleyab
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-best-practices
Source: https://github.com/coleYab/usacr/tree/main/.grok/skills/testing-best-practices
Command: npx skills add https://github.com/coleYab/usacr --skill testing-best-practices-coleyab

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing valuable Laravel tests is hard: teams often test framework behavior instead of application contracts, duplicate coverage across layers, or write flaky tests that depend on real time, randomness, and network calls. This Skill provides a structured rule set for designing, writing, and reviewing Pest and PHPUnit tests so every test detects a distinct defect. ## Core Features & Use Cases - Coverage and Naming Rules: Decide what to test, name tests as behavior specifications, and structure files to mirror the class under test. - Isolation and Determinism: Control time, randomness, sleep, outbound HTTP, and database state using Laravel fakes and Pest helpers. - Security and Endpoint Testing: Cover authentication, authorization, tenant isolation, validation messages, escaping, and injection boundaries. - Use Case: When adding a ticket purchase endpoint to a Laravel app, use this Skill to write feature tests covering authentication, validation failures, wallet debit side effects, and cross-tenant access, then review the suite against the review checklist. ## Quick Start Ask the assistant to write Pest feature tests for a specific Laravel controller or action following the testing-best-practices rules.

Frequently Asked Questions about testing-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write good Pest tests for a Laravel application?

Write feature tests first that cover observable behavior and application contracts, using arrange-act-assert structure with one blank line between parts. Name each test as a behavior specification stating the result and its condition, and assert the complete result including database state and side effects.

What should I test in Laravel HTTP endpoint tests?

Cover missing or invalid authentication, cross-tenant access, insufficient roles, route constraints, validation failures, and the valid case. Assert the application's actual behavior such as a 401 for API tokens or a redirect for browser endpoints, plus persisted state changes.

Should I use Pest or PHPUnit for Laravel testing?

This guidance assumes Pest, which this project uses, but the rules apply to both frameworks. Follow the conventions already present in neighboring test files, since project conventions take precedence over general rules.

How do I make Laravel tests deterministic and fast?

Use framework fakes for events, queues, mail, HTTP, time, and sleep instead of real implementations. Set BCRYPT_ROUNDS=4 in the test environment, use LazilyRefreshDatabase, and run pest with --parallel or --tia to reduce suite time.

When should I use mocks instead of fakes in Laravel tests?

Always prefer framework fakes for facades like events, queues, mail, and HTTP. Use a mock only for container-resolved contracts whose real implementation leaves the process or is nondeterministic, and use the real database rather than mocking the query builder.

Why do my Laravel tests fail only when run in parallel?

Parallel failures indicate tests reading records created by other tests, depending on run order, or sharing files, cache keys, or queues. Each test must create its own data and use process-specific names for shared resources.