Unit test: A test that verifies a single, isolated piece of functionality (a function, a method) in isolation from the rest of the system. The fastest and most granular type of test. A unit test checks a small piece of code, such as one function or method, in isolation from the rest of the system. It runs in milliseconds, without a database, network or file system.
Unit tests are ideal for logic with clear inputs and outputs: price calculations, date rules, validation, formatting. They pinpoint exactly what broke, because each test covers so little.
What should you keep in mind with Unit test?
They work best combined with other kinds of tests. Feature or integration tests check that parts work together, such as a request reaching the database and returning the right page. In Laravel, both live side by side in PHPUnit or Pest. A good habit is to write a failing test before fixing a bug. It proves the fix works and prevents the same bug from quietly returning.
Test-driven development with red-green-refactor loop using Pest PHP. Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants integration tests, asks for test-first development, or needs guidance on writing testable code with Pest.
Laravel 13 testing with Pest PHP 4 or PHPUnit 12. Use when writing feature tests, unit tests, or any test code in a Laravel application. Triggers on tasks involving HTTP tests, model factories, database assertions, mocking facades, authentication testing, or test organisation patterns.