testing-best-practices

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

Updated Aug 29, 2026
One-click install
npx skills add https://github.com/F41541/koperasi-app --skill testing-best-practices-f41541
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: testing-best-practices
Source: https://github.com/F41541/koperasi-app/tree/main/.agents/skills/testing-best-practices
Command: npx skills add https://github.com/F41541/koperasi-app --skill testing-best-practices-f41541

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 providing no value. This Skill provides a structured rule set for designing, writing, and reviewing PHPUnit-based Laravel tests so every test detects a distinct defect. ## Core Features & Use Cases - Test Design Rules: Nine rule files covering naming, assertions, endpoint coverage, test data, isolation with fakes and mocks, security boundaries, and suite performance. - Test Review Checklist: A systematic review process that checks test value, coverage, determinism, and assertion quality before completion. - Use Case: When adding a new API endpoint to a Laravel application, use this Skill to write feature tests covering authentication, authorization, validation, tenant isolation, and persisted state, then review them against the checklist. ## Quick Start Ask the agent to write tests for a Laravel controller or review an existing test suite 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 feature tests for Laravel endpoints?▼

Write one feature test per applicable case: missing authentication, cross-tenant access, insufficient role, failed validation, and the valid request. Assert the complete result including the response, database state, and dispatched jobs or notifications, using Laravel's named response assertions.

What is the difference between fakes and mocks in Laravel testing?▼

Framework fakes like Event::fake() or Http::fake() preserve the real code path and are preferred for facades such as queues, mail, and storage. Mocks via $this->mock() replace a container-resolved contract and should only be used when the real implementation leaves the process or is nondeterministic.

Should I use Pest or PHPUnit for Laravel tests?▼

This Skill's rules apply to PHPUnit, which the project uses, and defers syntax questions to the PHPUnit 13.3 documentation and Laravel's search-docs tool. Project conventions take precedence, so follow the framework already installed in the codebase.

How do I make Laravel tests deterministic?▼

Control time with $this->freezeTime() or $this->travelTo(), fix random strings with Str::createRandomStringsUsing(), replace sleeps with Sleep::fake(), and block network calls with Http::preventStrayRequests(). Each test must pass alone and in any order within the full suite.

Why is my Laravel test suite slow and how do I fix it?▼

Set BCRYPT_ROUNDS=4 in the test environment, disable XDebug and pcov, use LazilyRefreshDatabase, and run php artisan test --parallel with ParaTest. Profile with php artisan test --profile to find the slowest tests before changing project-wide settings.

When should I write a unit test instead of a feature test in Laravel?▼

Write a feature test first for every behavior reachable through a request. Reserve unit tests for logic that does not use the framework, such as value objects or pure calculations, since feature tests exercise real application behavior.