【问题标题】:How to run a single test case method in cakephp如何在 cakephp 中运行单个测试用例方法
【发布时间】:2017-01-19 15:58:12
【问题描述】:

我正在使用带有 xdebug 的 cakephp 测试(php 单元测试)来运行服务器端代码并​​监控终端的输出,而不是使用它进行验证。
所以,每次,我想从终端运行一些特定的 lib/controller/model 方法并查看输出,我必须注释掉其他测试用例函数。
我知道这可能不是正确的方法, 但我想知道,如果有办法,我可以围绕蛋糕测试建立一个包装器,它将采用我要运行的方法名称的参数?

【问题讨论】:

    标签: php cakephp phpunit xdebug


    【解决方案1】:

    无需编写包装脚本

    运行一种测试方法

    使用过滤选项:

    -> phpunit --help
    PHPUnit 4.4.1 by Sebastian Bergmann.
    
    Usage: phpunit [options] UnitTest [UnitTest.php]
           phpunit [options] <directory>
    ...
    Test Selection Options:
    
      --filter <pattern>        Filter which tests to run.
    

    例如:

    -> phpunit --debug --filter testValidationDefault tests/TestCase/Model/Table/PostsTableTest.php 
    PHPUnit 4.4.1 by Sebastian Bergmann.
    
    Configuration read from /var/www/cakephp.dev/phpunit.xml.dist
    
    
    Starting test 'App\Test\TestCase\Model\Table\PostsTableTest::testValidationDefault'.
    I
    
    Time: 130 ms, Memory: 9.75Mb
    
    OK, but incomplete, skipped, or risky tests!
    Tests: 1, Assertions: 0, Incomplete: 1.     
    www-data @ dev [ /var/www/cakephp.dev ]
    -> 
    

    【讨论】:

      【解决方案2】:

      要仅运行一项测试,请使用 cake 命令行工具中的过滤器选项:

      cake test app Model/Post --filter testGetAllPostsByAuthor
      

      适用于 CakePhp 2.2

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-25
        • 1970-01-01
        • 2014-07-22
        • 2014-11-23
        • 1970-01-01
        相关资源
        最近更新 更多