Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LadyC's avatar
Level 1

Laravel 5.6 Testing - No tests executed!

Hi, I'm trying to write my first PHPUnit Test in Laravel following the documentation guide and I tapped into a "strange" behavior. I've checked the internet, but unfortunately I haven't found so much help.

Basically, I've created a new test, running this two commands:

php artisan make:test UserTest
php artisan make:test UserTest --unit

two folders were created: tests/Unit and test/Feature. Both these classes extends TestCase, which is requested at the beginning of the file with use Tests\TestCase;. But this TestCase file is not created at the beginning (first strange behavior -> in one video on youtube, a guy says that that file was already there).

Actually, the missing files are two: TestCase.php and also CreatesApplication.php, which is required in TestCase.php.

I have found these files and added to the project. It does not give error, but it ignores the test function with an assertTrue(true). phpunit says "No tests executed!"

I tried the HTTP test in Feature/UserTest.php and it works. [NOTE: ! RECTIFIED HERE] .

So my question is:

  • These two files (TestCase.php, CreatesApplication.php) where supposed to be there? Should I have done the creation of the test in another way?
  • Why phpunit ignore the simple default test? What am I missing?

I thought: maybe it's a matter of tasks. I've read in the guide: that "Feature and Unit" folders are in charge of different kinds of tests. The guide says:

"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."

So maybe (it's just a personal thought, an attempt to guess) this simple "assertTrue" test is not included in the list of expected task? I said that, because I tried this HTTP test in Unit and it just ignored in the same way. (I'm new in PHPUnit and in testing, so I'm trying to understand better).

Thanks in advance for your help and have a nice day! :)

0 likes
4 replies
tykus's avatar
tykus
Best Answer
Level 104

How did you install the Laravel project? The fact that you state that the artisan commands created the tests/Feature and tests/Unit directories is strange as these directories ship with Laravel along with the TestCase.php and CreatesApplication.php files. It would seem therefore that the project was either upgraded from an older version of the framework which did not have the same structures or someone emptied the tests directory.

Sys32's avatar

What I found doing testing in my 5.6 app, is that by default phpunit in the phpunit.xml file is setup to only load files with Test.php as suffix. So in order for any test to load, feature or otherwise, must be named correctly.

So TestCase.php becomes TestCaseTest.php and CreatesApplication.php becomes CreatesApplicationTest.php

1 like
tykus's avatar

Disregard that @N3 comment, TestCase is the abstract parent of all of your test classes - it does not contain test examples that PHPUnit needs to run. Similarly CreatesApplication is trait that bootstaps the framework for the tests

LadyC's avatar
Level 1

Thanks for help, I've created the project from scratch using laravel new blog. Then I've followed this guide at the very beginning.

I've forgotten that at the very beginning I tried the testing with dusk (it's in the last part of this guide), but then it was not needed and I deleted that folder.

So that's why it did not created "TestCase.php" and "CreatesApplication.php" files this time.

Still I've not understood why it ignores some of my test function. Now I'm testing in Feature/UserTest.php this authentication testing with model factory and actingAs method, but it does not tell me anything in the phpunit output.

namespace Tests\Feature;

use Tests\TestCase;
use App\User;

public function testApplication()
    {
        $user = factory(User::class)->create();

        $response = $this->actingAs($user)
            ->get('/');

        $response->assertStatus(200);
    }

Please or to participate in this conversation.