Testing is used to check whether your application is working correctly.
Types of Testing
- Unit Testing
- Feature Testing
Create a Test:
Unit Test:
php artisan make:test CalculatorTest --unittests/
└── Unit/
└── CalculatorTest.phpFeature Test:
php artisan make:test LoginTesttests/
└── Feature/
└── LoginTest.phpTesting in Laravel is used to verify that the application works correctly. Laravel supports Unit Testing for individual methods and Feature Testing for complete application features like login, registration, and API endpoints. Tests are created using Artisan and run with php artisan test.
Scenario
Route::get('/hello', function () {
return "Hello Laravel";
});Create Future Test
php artisan make:test HelloTest<?php
namespace Tests\Feature;
use Tests\TestCase;
class HelloTest extends TestCase
{
public function test_hello_page()
{
$response = $this->get('/hello');
$response->assertStatus(200);
$response->assertSee('Hello Laravel');
}
}Run Test:
php artisan test