PHPUnit - 'No tests executed' when using configuration file

后端 未结 22 698
故里飘歌
故里飘歌 2021-01-31 00:47

The Problem

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.

22条回答
  •  孤独总比滥情好
    2021-01-31 01:43

    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:

    ...
    
    
        
        ./tests/Unit
    
    
    
    
        
        ./tests/Feature
    
    
    ...
    

    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

提交回复
热议问题