testing-best-practices

Guides design, writing, and review of Laravel Pest tests.

Updated Sep 10, 2026
One-click install
npx skills add https://github.com/alemamdevs/expense-tracker --skill testing-best-practices-alemamdevs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-best-practices
Source: https://github.com/alemamdevs/expense-tracker/tree/main/.agents/skills/testing-best-practices
Command: npx skills add https://github.com/alemamdevs/expense-tracker --skill testing-best-practices-alemamdevs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing Laravel tests that actually catch defects is hard: tests often assert framework behavior, duplicate coverage, depend on real time or network, or pass while testing nothing. This Skill provides a structured rule set for designing, writing, and reviewing Pest tests so each test detects a distinct defect. ## Core Features & Use Cases - Test Design Rules: Nine rule files covering naming, assertions, endpoint coverage, test data, isolation, security, performance, and review checklists. - Coverage Guidance: Directs testing of authentication, authorization, tenant isolation, validation, and security boundaries like escaping and injection. - Determinism & Performance: Enforces fakes for time, sleep, HTTP, and events, plus CI settings like BCRYPT_ROUNDS and parallel execution. - Use Case: When adding a new API endpoint, use this Skill to write feature tests covering auth failures, validation errors, cross-tenant access, and the complete persisted result, then review the suite against the checklist. ## Quick Start Ask the agent to write or review Pest tests for a Laravel class or endpoint using 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 endpoint?

Write a feature test for each applicable case: missing authentication, insufficient role, cross-tenant access, failed validation, and the valid request. Assert both the response and the persisted database state, using named Laravel response assertions rather than raw status codes.

What should I test in a Laravel application?

Test observable behavior and application contracts, covering every changed decision and high-value failure mode. Leave framework behavior to framework tests, and exercise declarations like casts, scopes, and validation rules through behavior rather than asserting their text.

Should I use mocks or fakes in Laravel tests?

Prefer Laravel framework fakes for facades like events, queues, mail, notifications, storage, HTTP, time, and sleep, since they preserve the real code path. Use mocks only for container-resolved contracts whose real implementation leaves the process or is nondeterministic.

How do I make a slow Laravel test suite faster?

Set BCRYPT_ROUNDS=4 in the test environment, disable XDebug, use LazilyRefreshDatabase, and add global fakes for HTTP, sleep, and exceptions. Run vendor/bin/pest --parallel to spread tests across CPU cores and --profile to find the slowest tests.

When should I use datasets in Pest tests?

Use datasets when setup, test body, and assertions stay the same across input values, such as enum cases, roles, boundary values, or invalid inputs. Write separate tests when cases need different setup, behavior, or assertions, and name each dataset case.