Testing: Getting Started
Laravel is built with testing in mind. In fact, support for testing with PHPUnit is included out of the box and a file is already set up for your application. The framework also ships with convenient helper methods that allow you to expressively test your applications.
By default, your application's tests
directory contains two directories: Feature
and Unit
. Unit tests are tests that focus on a very small, isolated portion of your code. In fact, most unit tests probably focus on a single method. Feature tests may test a larger portion of your code, including how several objects interact with each other or even a full HTTP request to a JSON endpoint.
When running tests via phpunit
, Laravel will automatically set the configuration environment to testing
because of the environment variables defined in the phpunit.xml
file. Laravel also automatically configures the session and cache to the array
driver while testing, meaning no session or cache data will be persisted while testing.
To create a new test case, use the make:test
Artisan command:
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
{
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}