681 0 0 0
Last Updated : 2025-04-28 21:32:58
In this article we will just show few examples and guide lines for Unit Testing in Laravel applications.
There are two areas for testing:
//Running the test from your terminal
vendor\bin\phpunit //Laravel 10
phpunit //Laravel 7
//---------------------------------------------------------- EXAMPLE TESTS
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
//----------------------------------------------------A list of possible testing methods
//Full list of assertions are found here : https://phpunit-document-english.readthedocs.io/en/latest/assertions.html
$response->assertStatus(200);
$response->assertSee(''Laravel); //Will check if the response page has the text 'Laravel' on it
$response->AssertDontSee('This text shall not be on the page to pass the test'); //Will check if the text is NOT there
$this->assertTrue(true);