To test a Laravel application, choose a test boundary that matches the behavior you need to trust, prepare predictable state, exercise that behavior, and assert what an external observer can see. Laravel supports Pest and PHPUnit, and you can run either suite through php artisan test. Use Unit tests for isolated calculations; use Feature tests when behavior crosses framework services, database records, middleware, or HTTP requests.
This guide uses Laravel 12 documentation for test setup and database workflows, plus Laravel 13 documentation for HTTP testing. Check the documentation for your installed version before copying version-sensitive examples: Laravel’s current search results identify 12.x as an older documentation branch. Laravel 12 testing guide
Choose the test boundary: Unit or Feature
Start with the question the test should answer: does one isolated piece of logic produce the right result, or does the application behave correctly when its parts work together?
| Test type | Best for | Application and framework access | Trade-off |
|---|---|---|---|
| Unit | A small class or calculation whose inputs and outputs can be tested in isolation. | Laravel says Unit tests do not boot the application, so they cannot access the database or other framework services. | Focused isolation; does not prove that routing, persistence, middleware, or framework integration works. |
| Feature | Several objects working together, or an application flow such as a full request to a JSON endpoint. | Can exercise the application and its framework behavior. | Broader confidence in system behavior, with more setup and scope than a narrow unit check. |
Laravel’s guidance is that “Generally, most of your tests should be feature tests.” That is not a rule to avoid Unit tests: keep calculations and other genuinely isolated behavior at the narrow boundary where the test stays clear. Use Feature tests when integration is the point. Laravel 12: Testing: Getting Started
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Create a test and run the suite
Laravel 12 documents both Pest and PHPUnit. The project’s existing setup determines which runner and syntax to use; the documentation does not prescribe one over the other.
- Create a default Feature test:
php artisan make:test ExampleTest. - Create a Unit test instead:
php artisan make:test ExampleTest --unit. - Open the generated test and add an assertion that would fail if the behavior were wrong. Generation alone does not test anything meaningful.
- Run the suite with Laravel’s Artisan runner:
php artisan test. Alternatively, usevendor/bin/pestorvendor/bin/phpunit, depending on the installed test framework.
Laravel 12 documents a preconfigured phpunit.xml. Its upgrade guidance associates Laravel 12 with laravel/framework ^12.0, PHPUnit ^11.0, and Pest ^3.0; these are version constraints in that upgrade reference, not a reason to upgrade an existing project solely to follow this guide. Laravel 12 upgrade guide
Keep the testing environment predictable
Tests use the testing environment. Laravel documents the session and cache drivers as array by default in tests, which keeps those services from relying on the corresponding persistent stores during a test run.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
- Use
.env.testingfor test-specific environment values; it can override.envwhile tests run. - Keep test database credentials and other required service configuration explicit and safe for a test environment.
- After changing environment settings that are affected by cached configuration, clear the configuration cache before testing:
php artisan config:clear.
These settings are setup controls, not assertions: a predictable environment reduces accidental dependence on a developer’s local state, but each test still needs to arrange the state its scenario requires. Laravel 12 testing configuration
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Test database behavior with isolated records
When a test depends on persistence, reset database state deliberately. Laravel’s RefreshDatabase trait is the usual starting point: when the schema is already current, Laravel runs each test inside a transaction instead of migrating the database for every test.
- Use a Feature test for the application behavior that reads or writes records.
- Add
use IlluminateFoundationTestingRefreshDatabase;and theRefreshDatabasetrait to the test class. - Create only the records the scenario needs with model factories.
- Perform the request or application action.
- Assert both the observable response and the persisted database state when both matter.
For example, the class setup can look like this:
<?php
namespace TestsFeature;
use IlluminateFoundationTestingRefreshDatabase;
use TestsTestCase;
class OrderTest extends TestCase
{
use RefreshDatabase;
public function test_order_is_saved(): void
{
// Create the required records, exercise the behavior,
// then assert the response and database state.
}
}
Use a seeder when the scenario specifically depends on seeded application data; factories are more targeted for ordinary test records. Laravel also documents DatabaseMigrations and DatabaseTruncation, but describes them as significantly slower than the transaction-based approach where it applies. Laravel 12 database testing
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Test an HTTP endpoint and API response
HTTP tests make requests to the application and let you inspect responses without needing to operate a real browser. Laravel’s documented HTTP-testing coverage includes JSON APIs, uploads, views, sessions, authentication, validation, and response assertions. The Laravel 13 HTTP Tests page is used here for this API surface; confirm exact methods against the documentation version matching your application. Laravel 13 HTTP Tests
A minimal JSON endpoint test follows this shape; replace the route and expected fields with the contract your application actually exposes:
Recommended Free Tools
public function test_status_endpoint_returns_json(): void
{
$response = $this->getJson('/api/status');
$response->assertOk()
->assertJsonPath('status', 'ok');
}
For a persistence-backed endpoint, combine the HTTP request with the database setup described above, then assert the response and stored row. For validation behavior, submit invalid input and assert the validation response rather than only checking that the request failed. For uploads, use Laravel’s upload-testing support and assert the resulting application behavior, such as the response or stored metadata.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Authenticate a Sanctum API request
For Sanctum-protected routes, Laravel’s Sanctum testing documentation shows using Sanctum::actingAs with a factory-created user before making the request. A representative test shape is:
use AppModelsUser;
use LaravelSanctumSanctum;
$user = User::factory()->create();
Sanctum::actingAs($user);
$response = $this->getJson('/api/user');
$response->assertOk();
Use the endpoint and authorization abilities appropriate to your application; a successful response alone does not prove that authorization rules reject users who lack access. Laravel 12 Sanctum testing
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Run tests in parallel after sequential runs are reliable
Parallel execution can reduce waiting on a larger suite, but it also consumes more machine resources and requires isolation for shared data. Laravel 12 documents this setup:
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
- Install ParaTest as a development dependency:
composer require brianium/paratest --dev. - Run tests in parallel:
php artisan test --parallel. - Adjust the process count to the resources available to the test machine if needed; Laravel’s documentation illustrates
--processes=4as a command example, not as a universal optimal value.
With a primary database configured, Laravel creates and migrates a separate test database for each process, using a process token in its name. Those database names persist between runs unless you request recreation with --recreate-databases. If tests share other resources, use parallel testing lifecycle hooks such as ParallelTesting hooks to segment or prepare them per process. Do not rely on one test’s changes being visible to another. Laravel 12 parallel testing
Common failures and practical fixes
- A Unit test cannot use the database or Laravel services: that is expected because Unit tests do not boot the application. Move an integration scenario to a Feature test.
- Tests pass locally but use unexpected configuration: inspect
.env.testingand clear configuration cache withphp artisan config:clearafter relevant changes. - A database test leaks state or depends on execution order: apply a reset strategy such as
RefreshDatabase, create the needed records in the test, and assert its own outcome. - Parallel tests conflict over a shared resource: isolate that resource per process using process-aware setup or lifecycle hooks; separate databases do not automatically isolate files, external services, or other shared stores.
- A test command or example does not match the project: check the installed Laravel, Pest, and PHPUnit versions and use their matching documentation rather than combining Laravel 12 setup details with Laravel 13 HTTP examples.
Or skip the browser setup
Laravel tests should verify application behavior directly; taking a website screenshot is a separate task. If you need a screenshot of a page for documentation or a visual workflow, ScreenshotNeo provides a screenshot API and MCP server. One GET request returns an image or PDF; see the API documentation.
Quick Recap
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each cleanup step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers report the page verdict and billing status.
- An MCP server provides
take_screenshot,get_page_info, andcapture_pdftools for AI agents. - The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




