PHPUnit入门

2017-07-13  本文已影响0人  钟晃

选择当前创建 phpunit.xml,之后在该目录下执行phpunit即可进行单元测试了
示例 phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- bootstrap表示引导脚本,通常实现了__autoload函数或者使用spl_autoload_register注册自动加载方法  -->
<phpunit stopOnFailure="true" bootstrap="engine.inc">
    <testsuites>
        <!-- 测试套件:全部 -->
        <testsuite>
             <!-- 表示测试test目录下所有Test.php后缀的文件 -->
            <directory suffix="Test.php">test</directory>
        </testsuite>
        <!-- 测试套件:bundle -->
        <testsuite name="bundle">
            <directory suffix="Test.php">test/bundle</directory>
        </testsuite>
    </testsuites>
    <!-- 测试过滤 -->
    <filter>
        <!-- 白名单 -->
        <whitelist>
            <directory>test</directory>
           <!-- 白名不包括 -->
            <exclude>
                <!-- 过滤文件夹 -->
                <directory>test/XXX</directory>
                <!-- 过滤指定的文件 -->
                <file>test/XXX.php</file>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

测试命令如下:

phpunit
phpunit test/core/
phpunit test/core/CacheTest.php
# 或者不加php后缀
phpunit test/core/CacheTest 

4.测试套件

phpunit --testsuite [suitname]
上一篇下一篇

猜你喜欢

热点阅读