I have a fresh installation of laravel 5.4
I've tried to modify the default test just to see a failing test.
tests/ExampleTest.php
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/ooops');
$response->assertStatus(200);
}
}
I was expecting to see more detailed error like no route has been found or defined
etc, but instead just this error saying
Time: 1.13 seconds, Memory: 8.00MB
There was 1 failure:
1) Tests\Feature\ExampleTest::testBasicTest
Expected status code 200 but received 404.
Failed asserting that false is true.
/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:51
/var/www/tests/Feature/ExampleTest.php:21
Its really hard to do TDD without meaningful error (yeah I know 404 in this case is enough, but most of the time its not the case).
Is there a way to enable the stacktrace the same as the one displayed on the browser? Or at least closer to that one so that I know what's the next step I should do.
Thanks in advance.
For Laravel 5.4 you can use
disableExceptionHandling
method presented by Adam Wathan in this gist (source code below)Now if you run in your test:
you should get full info that will help you to find the problem.
For Laravel 5.5 and up you can use
withoutExceptionHandling
method that is built-in into LaravelSource code of Adam Wathan's gist
If you happen to use Laravel 5.5 and up, you can use the built-in methods:
Either in your setUp method, or in your test method's. They are defined in the following trait.
For quick and dirty debugging, you can also use the
dump
method on theresponse
object:There is a laracast lesson that covers these details.