PHPUnit - 'No tests executed' when using configuration file
On windows use the following command on terminal
.\vendor\bin\phpunit
that's if the command
phpunit
returns "No tests executed!"
while on Mac
./vendor/bin/phpunit
Hope it helps.
I had the same problem after PHPUnit on our virtual machines updated to version 6. Even --debug and --verbose said nothing useful, just "No tests executed". In the end it turned out that classes and namespaces were changed in the new version and it just didn't want to execute the files that contained references to old classes. The fix for me was just to replace in every test case this:
class MyTestCase extends \PHPUnit_Framework_TestCase {...}
with:
use PHPUnit\Framework\TestCase;
class MyTestCase extends TestCase {...}
For what it's worth (being late), I ran into this recently while I was making a new Laravel 5.1 project for a simple website. I tried to debug it and was confused when I tried:
php artisan make:test homeTest
(which has a default test that just asserts true is true)
and saw the output
No tests executed!
What the problem ended up being for me was related to my PHP installation -- "phpunit" was globally registered and configured differently, whereas the phpunit that came with the Laravel installation was configured just right and ran perfectly.
So the fix is running the vendor's configured phpunit (from the same root directory as app/ and tests/):
./vendor/bin/phpunit
Hope that helps someone else!
Your XML file is fine as it is. However, you have to make sure that the PHP files in your tests/
folder are named as follows:
tests/Test.php <--- Note the uppercase "T"
tests/userTest.php
tests/fooBarTest.php
etc.
The filenames must end with "Test.php". This is what PHPUnit is looking for within directories.
Furthermore, every test method must either have a name that starts with "test" OR an @test
annotation:
public function testFooBar()
{
// Your test code
}
or:
/**
* @test
*/
public function fooBarTest() {
// test code here
}
Hope that helps!