PHPUnit - 'No tests executed' when using configuration file

后端 未结 22 693
故里飘歌
故里飘歌 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:38

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

    0 讨论(0)
  • 2021-01-31 01:40

    Instead of run phpunit

    use

    vendor\bin\phpunit

    0 讨论(0)
  • 2021-01-31 01:40

    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

    0 讨论(0)
  • 2021-01-31 01:42

    You Need Just To Call It From Vendor File

    vendor\bin\phpunit Notice \ Not /

    0 讨论(0)
  • 2021-01-31 01:42

    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.

    0 讨论(0)
  • 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:

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

    0 讨论(0)
提交回复
热议问题