To improve my quality of code, I\'ve decided to try to learn how to test my code using Unit Testing instead of my mediocre-at-best testing solutions.
Check phpunit.xml file, look inside testsuites.
My version of phpunit (2019) is looking for files ending (suffix) *Test.php . So, make sure all the test files are named properly (ex.: BookTest.php is correct, BookTests.php is not, BookTestCase.php is not).
Instead of run phpunit
use
vendor\bin\phpunit
using de cmd console resolved this problem passing the enterely path Test realized
I did't find another way to do it It does not work from this way
I hope this was helpful for someone
You Need Just To Call It From Vendor File
vendor\bin\phpunit
Notice \ Not /
If you are using IDEs like JetBrains PHPStorm, please also notice that: in the Run/Debug Configurations
window, the Test scope
needs to be set to directory
and point that directory to where your tests
folder located.
It just took me half an hour to figure out I forgot to set the directory. You can use global phpunit.phar
as long as you set test scope and the directory correctly, the IDE will handle other stuff for you.
Came late to the party, but this info may help others.
Above solutions did not work for me. As of Laravel 7.x, by default, PHPUnit executes only PHP files which are suffixed with "Test.php". For example if you create a test, naming it CreateUser
will not work, whereas naming it CreateUserTest
will work.
To overcome the limitation, go to phpunit.xml
and modify suffix
attribute from directory
elements:
...
<testsuite name="Unit">
<!-- modify suffix -->
<directory suffix=".php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<!-- modify suffix -->
<directory suffix=".php">./tests/Feature</directory>
</testsuite>
...
This will instruct PHPUnit to run all files with .php
extension from directories. Note to clear app's cache after updating phpunit.xml
:
php artisan config:cache
Additional information about PHPUnit XML configuration can be found here: https://phpunit.de/manual/6.5/en/appendixes.configuration.html