zoukankan      html  css  js  c++  java
  • yaf框架编写phpunit测试用例

    phpunit中文文档:
     
    目录结构:
    test ├── controllers │ ├── BaseControllerTest.php │ └── IndexControllerTest.php ├── modules │ └── Testdemo
    │ │ ├── controllers
    │ │ │ ├── ApiTest.php
    ├── index.php ├── phpunit.xml └── composer.json
     
    在tests目录下放置composer.json文件:
     
    {
    "require-dev": {
    "phpunit/phpunit": "^6.1",
    "phpunit/php-invoker": "^1.1",
    "phpunit/dbunit": "^3.0"
    }
    }
    安装composer:composer install
     
    入口文件配置:tests/index.php
     
    <?php
     
    date_default_timezone_set("Asia/Shanghai");
     
    define('ENVIRONMENT', 'develop');
    include './vendor/autoload.php';
     
    define('APPLICATION_PATH', dirname(dirname(__FILE__)));
    define("VIEWS_PATH", APPLICATION_PATH."/application/views");
     
    $application = new Yaf_Application( APPLICATION_PATH . "/conf/application.ini");
     
    $application->bootstrap()->run();
    ?>
     
    在tests/phpunit.xml文件中引入入口文件:
    <phpunit bootstrap="./index.php">
    <testsuites>
    <!--<testsuite name="controllers">-->
    <!--<file>./controllers/DemoTest.php</file>-->
    <!--</testsuite>-->
    <!--<testsuite name="models">-->
    <!--<file>./models/UserTest.php</file>-->
    <!--</testsuite>-->
    <!--<testsuite name="models/Mysql">-->
    <!--<file>./models/Mysql/UserTest.php</file>-->
    <!--</testsuite>-->
    <!--<testsuite name="models/Redis">-->
    <!--<file>./models/Redis/UserTest.php</file>-->
    <!--</testsuite>-->
    <!--<testsuite name="modules/Testdemo">-->
    <!--<file>./modules/Testdemo/controllers/ApiTest.php</file>-->
    <!--</testsuite>-->
    </testsuites>
    </phpunit>
     
    在tests目录下运行ApiTest测试文件命令行:
    phpunit --stderr ./modules/Testdemo/controllers/ApiTest.php 注:--stderr 是指直接输出,不会经过缓存,屏蔽header带出来的错误
    phpunit --stderr --filter 'testIndex' ./modules/Testdemo/controllers/ApiTest.php 注:'testIndex'是指只运行ApiTest.php里边的Index测试块,即testIndex方法

  • 相关阅读:
    团队作业4--项目冲刺
    第七篇Scrum冲刺博客--Interesting-Corps
    第六篇Scrum冲刺博客--Interesting-Corps
    第五篇Scrum冲刺博客--Interesting-Corps
    第四篇Scrum冲刺博客--Interesting-Corps
    第三篇Scrum冲刺博客--Interesting-Corps
    第二篇Scrum冲刺博客--Interesting-Corps
    团队作业6——复审与事后分析
    alpha阶段项目复审
    团队作业5—测试与发布说明
  • 原文地址:https://www.cnblogs.com/wupeiky/p/9329047.html
Copyright © 2011-2022 走看看