laravel-tdd

Create Laravel unit and feature tests with PHPUnit or Pest.

Updated Sep 13, 2025
One-click install
npx skills add https://github.com/llmh333/employee_management_spring --skill laravel-tdd-llmh333
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-tdd
Source: https://github.com/llmh333/employee_management_spring/tree/main/.gemini/skills/laravel-tdd
Command: npx skills add https://github.com/llmh333/employee_management_spring --skill laravel-tdd-llmh333

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of fragile or incomplete Laravel test coverage by guiding a disciplined test-driven workflow that keeps unit, feature, and integration tests green.

Core Features & Use Cases

  • Test-driven development workflow: Use the red-green-refactor cycle to write failing tests first, implement minimal changes, then refactor safely.
  • Correct test layering: Choose the right test type—unit for pure logic, feature for HTTP/auth/validation/policies, integration when multiple boundaries (DB/queues/externals) must work together.
  • Reliable database testing: Default to RefreshDatabase for most DB tests, and switch to DatabaseTransactions or DatabaseMigrations when the schema or rollback strategy requires it.
  • Deterministic side-effect testing: Use fakes for queues, mail, notifications, events, buses, and HTTP calls to isolate external dependencies.
  • Coverage-first guidance: Target 80%+ coverage for unit + feature tests and run via phpunit/pest in CI with coverage tooling.

Quick Start

Tell the AI to create a failing Pest feature test for a new Laravel endpoint, then outline the minimal implementation and database assertions needed to make it pass with RefreshDatabase.

Frequently Asked Questions about laravel-tdd

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

FAQPage Schema
How do I write reliable Laravel feature tests using TDD?

Laravel feature tests using TDD require a red-green-refactor cycle: write a failing Pest or PHPUnit test for the endpoint, implement minimal code to pass, then refactor. Use RefreshDatabase for most DB tests and isolate external interactions with fakes.

When should I use RefreshDatabase vs DatabaseTransactions in PHPUnit tests?

Use RefreshDatabase for most database tests to ensure a clean schema state. Switch to DatabaseTransactions or DatabaseMigrations when your test suite requires specific rollback strategies or schema modifications between test runs.

How do I test queued jobs and external HTTP calls in Laravel?

Test queued jobs and external HTTP calls in Laravel by using framework fakes. Queue, mail, notification, event, bus, and HTTP fakes isolate external dependencies, ensuring deterministic side-effect testing without hitting actual services.

Can I use Pest for test-driven development in Laravel instead of PHPUnit?

Yes, Pest works for test-driven development in Laravel. The workflow supports both PHPUnit and Pest to write failing tests first, implement minimal changes, and refactor safely while enforcing 80%+ coverage in CI.

What is the correct test layering for Laravel Eloquent behavior and policies?

Correct Laravel test layering uses unit tests for pure logic and feature tests for HTTP, auth, validation, and policies. Integration tests are necessary when multiple boundaries like databases, queues, and external APIs must work together.

Why does my Laravel test coverage drop when refactoring endpoints?

Laravel test coverage drops during endpoint refactoring when the red-green-refactor cycle is skipped. Maintain 80%+ coverage by writing failing tests first, implementing minimal changes, and running coverage tooling via PHPUnit or Pest in CI.