Laravel - Getting Started - Creating Tests
To create a new test case, use the make:test
Artisan command. By default, tests will be placed in the tests/Feature
directory:
php artisan make:test UserTest
If you would like to create a test within the tests/Unit
directory, you may use the --unit
option when executing the make:test
command:
php artisan make:test UserTest --unit
If you would like to create a Pest PHP test, you may provide the --pest
option to the make:test
command:
php artisan make:test UserTest --pest
php artisan make:test UserTest --unit --pest
Test stubs may be customized using stub publishing.
Once the test has been generated, you may define test methods as you normally would using PHPUnit. To run your tests, execute the vendor/bin/phpunit
or php artisan test
command from your terminal:
assertTrue(true);
}
}
If you define your ownsetUp
/tearDown
methods within a test class, be sure to call the respectiveparent::setUp()
/parent::tearDown()
methods on the parent class.