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.
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! :)
Please or to participate in this conversation.