PHPUnit - 'No tests executed' when using configuration file

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

    I pulled my hair for 10 minutes before i decided to use --debug (good way to go by the way) to discover the simple fact that file name didn't respect the naming convention, i had an extra "s" at the end.

    wrong

    CreateAdminTests
    

    right

    CreateAdminTest
    

    hope this note could help for someone

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

    This is very late but I hope it helps someone.

    I got my tests to run by using an absolute reference. folder structure [ project/tests/test.php]

    my directory line looked like this ./tests/test.php

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

    I realize this is super old, but it just happened to me too. Hopefully this will help someone.

    My problem was that I forgot the '@' symbol in /** @test */

    WRONG:

    /** test */
    function a_thread_can_be_deleted()
    {
        ...
    }
    

    RIGHT:

    /** @test */
    function a_thread_can_be_deleted()
    {
        ...
    }
    
    0 讨论(0)
  • 2021-01-31 01:34

    I had the issue of no tests being executed, even when things were set up fine.

    The cause was the namespace was not the first command of the file, it was after some doc-block comments.

    reverting caused phpunit to see the tests and run correctly.

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

    For me, using phpunit --debug showed me which test it was not executing, inside, I had

    $this->visit('/')
             ->see('Laravel');
    

    and I think because the directory was protected with .htaccess authentication, it could not get through to visit the page

    The solution for me was to take out this test (or most likely take out .htaccess authentication)

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

    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 {...}
    
    0 讨论(0)
提交回复
热议问题