How to run single test method with phpunit?

前端 未结 13 2097
猫巷女王i
猫巷女王i 2020-11-30 16:13

I am struggling to run a single test method named testSaveAndDrop in the file escalation/EscalationGroupTest.php with phpunit. I tried

相关标签:
13条回答
  • 2020-11-30 16:51

    You Can try this i am able to run single Test cases

    phpunit tests/{testfilename}
    

    Eg:

    phpunit tests/StackoverflowTest.php
    

    If you want to run single Test cases in Laravel 5.5 Try

    vendor/bin/phpunit tests/Feature/{testfilename} 
    
    vendor/bin/phpunit tests/Unit/{testfilename} 
    

    Eg:

    vendor/bin/phpunit tests/Feature/ContactpageTest.php 
    
    vendor/bin/phpunit tests/Unit/ContactpageTest.php
    
    0 讨论(0)
  • 2020-11-30 16:51

    If you're using an XML configuration file, you can add the following inside the phpunit tag:

    <groups>
      <include>
        <group>nameToInclude</group>
      </include>
      <exclude>
        <group>nameToExclude</group>
      </exclude>
    </groups>
    

    See https://phpunit.de/manual/current/en/appendixes.configuration.html

    0 讨论(0)
  • 2020-11-30 16:54

    The reason your tests are all being run is that you have the --filter flag after the file name. PHPUnit is not reading the options at all and so is running all the test cases.

    From the help screen:

     Usage: phpunit [options] UnitTest [UnitTest.php]
            phpunit [options] <directory>
    

    So move the --filter argument before the test file that you want as mentioned in @Alex and @Ferid Mövsümov answers. And you should only have the test that you want run.

    0 讨论(0)
  • 2020-11-30 16:56

    The following command runs the test on a single method:

    phpunit --filter testSaveAndDrop EscalationGroupTest escalation/EscalationGroupTest.php
    
    phpunit --filter methodName ClassName path/to/file.php
    

    For newer versions of phpunit, it is just:

    phpunit --filter methodName path/to/file.php
    
    0 讨论(0)
  • 2020-11-30 16:56

    If you're in netbeans you can right click in the test method and click "Run Focused Test Method".

    Run Focused Test Method menu

    0 讨论(0)
  • 2020-11-30 16:58

    You must use --filter to run a single test method php phpunit --filter "/::testMethod( .*)?$/" ClassTest ClassTest.php

    The above filter will run testMethod alone.

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