PHPUnit教程(五)PHPUnit参数详解

发布时间:2020-01-02编辑:脚本学堂
本文是PHPUnit系列教程的第五篇,详细介绍了PHPUnit中的参数用法,有需要的朋友作个参考。

本节主要内容:
PHPUnit参数详解   

说明:本文直接翻译自PHPUnit官方文档,个人翻译水平有限,可能会存在某些词和意思翻译不准的地方,大家凑和看,呵呵。

    Runs the tests that are provided by the class UnitTest. This class is expected to be declared in the UnitTest.php sourcefile.
    UnitTest must be either a class that inherits from PHPUnit_Framework_TestCase or a class that provides a public static suite() method which returns an PHPUnit_Framework_Test object, for example an instance of the PHPUnit_Framework_TestSuite class.
    运行类UnitTest提供的所有测试,这个类需要定义在UnitTest.php这个文件中.
    类UnitTest需要从PHPUnit_Framework_TestCase继承或者提供一个公开的静态方法suite()返回一个PHPUnit_Framework_Test对象的实例.
   
phpunit UnitTest Test.php
    Runs the tests that are provided by the class UnitTest. This class is expected to be declared in the specified sourcefile.
    运行UnitTest提供的所有测试,这个类应该在定义在Test.php中
   
--log-junit

    Generates a logfile in JUnit XML format for the tests run.
    生成JUnit XML格式的日志文件

--log-tap

    Generates a logfile using the Test Anything Protocol (TAP) format for the tests run.
    生成TAP格式的日志文件
   
--log-dbus

    Log test execution using DBUS.
    使用DBUS记录测试的执行情况

--log-json

    Generates a logfile using the JSON format.
    生成JSON格式的日志文件
   
--coverage-html

    Generates a code coverage report in HTML format.
    生成html格式的代码覆盖报告

    Please note that this functionality is only available when the tokenizer and Xdebug extensions are installed.
    请注意这个功能只能在tokenizer和Xdebug安装后才能使用

--coverage-clover

    Generates a logfile in XML format with the code coverage information for the tests run.
    生成xml格式的代码覆盖报告

    Please note that this functionality is only available when the tokenizer and Xdebug extensions are installed.
    请注意这个功能只能在tokenizer和Xdebug安装后才能使用

--testdox-html and --testdox-text

    Generates agile documentation in HTML or plain text format for the tests that are run.
    生成记录已运行测试的html或者纯文本格式的文件文档

--filter

    Only runs tests whose name matches the given pattern. The pattern can be either the name of a single test or a regular expression that matches multiple test names.

    只运行名字符合参数规定的格式的测试,参数可以是一个测试的名字或者一个匹配多个测试名字的正则表达式

--group

    Only runs tests from the specified group(s). A test can be tagged as belonging to a group using the @group annotation.
    只运行规定的测试组,一个测试可以使用@group注释来分组
    The @author annotation is an alias for @group allowing to filter tests based on their authors.
    @author注视是一个和@group关联的注释标签,用来根据作者来过滤测试

--exclude-group

    Exclude tests from the specified group(s). A test can be tagged as belonging to a group using the @group annotation.
    只包含规定的多个测试组,一个测试可以使用@group注释来分组

--list-groups

    List available test groups.
    列出可用的测试组
   
--loader

    Specifies the PHPUnit_Runner_TestSuiteLoader implementation to use.
    定义使用PHPUnit_Runner_TestSuiteLoader的接口

    The standard test suite loader will look for the sourcefile in the current working directory and in each directory that is specified in PHP's include_path configuration directive. Following the PEAR Naming Conventions, a class name such as Project_Package_Class is mapped to the sourcefile name Project/Package/Class.php.
    标准的standard test suite loader会在当前的目录和php的include_path中根据PEAR的命名规则的类,一个叫做Project_Package_Class的类 会指向到文件Project/Package/Class.php
   
--repeat

    Repeatedly runs the test(s) the specified number of times.
    根据定义的数字重复运行测试
   
--tap

    Reports the test progress using the Test Anything Protocol (TAP).
    使用Test Anything Protocol格式报告测试进程
   
--testdox

    Reports the test progress as agile documentation.
    使用agile documentation格式报告测试进程

--colors

    Use colors in output.
    在输出结果中使用颜色

--stderr

    Optionally print to STDERR instead of STDOUT.
    使用STDERR替代STDOUT输出结果

--stop-on-error

    Stop execution upon first error.
    在遇到第一个错误时停止执行
   
--stop-on-failure

    Stop execution upon first error or failure.
    在遇到第一个失败时停止执行
   
--stop-on-skipped

    Stop execution upon first skipped test.
    在遇到第一个跳过的测试时停止执行