PHPUnit - 'No tests executed' when using configuration file

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

    if you are using PHPSTORM go to Settings then goto

    • Test Frameworks

      and click + and choose

    • PHPUnit Local then

    • Use Composer Auto Loader then paste this like in path to script field

    • C:\{YOUR PROJECT NAME}\vendor\autoload.php

    • click OK

    • HAPPY TESTING

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

    I had the same issue of No tests executed!, solved by keeping the same name of file and class name.

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

    The function names in the test file must either be prefixed with test or there should be a comment added before function

    /** @test */
    

    Make sure that it is not

    /* @test */
    

    because that doesn't work. there needs to be two asterisks after slash not one.

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

    Mine was a bit funny.

    When I used php artisan make:test I accidentally put .php like ProductRewardPointController.php which created ProductRewardPointController.php.php and phpunit simply ignored it.

    I just delete the extra .php and things back to normal

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

    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 have a name that starts with "test":

    public function testFooBar()
    {
        // Your test code
    }
    

    Hope that helps!

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

    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!

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