Testing
Feature tests exercise HTTP and persistence; unit tests isolate rules.
What it is
Feature tests exercise HTTP and persistence; unit tests isolate rules.
When to use it
Prove important behavior, including denied access and boundaries.
Syntax
php artisan testExample
use Illuminate\Foundation\Testing\RefreshDatabase;
class OrderTest extends TestCase
{
use RefreshDatabase;
public function test_guest_cannot_create_order(): void
{
$this->postJson("/orders", ["total_cents" => 1250])->assertUnauthorized();
}
}Common mistakes
Default Laravel feature tests bypass CSRF; explicitly re-enable it for CSRF tests; SQLite cannot prove production lock behavior.