|
PHPUnit命令行测试工具是通过phpunit命令调用的。如下代码显示如何通过PHPUnit命令行测试工具运行测试。
phpunit ArrayTest PHPUnit 2.3.0 by Sebastian Bergmann.
Time: 0.067288
OK (2 tests)
对每个测试,PHPUnit命令行测试工具打印一个字符表示进程:
·测试成功打印“.”。
·运行测试方法是发生了断言失败打印“F”。
·运行测试方法是发生了错误打印“E”。
·测试没有完成或测试没有实现打印“I”(见本书后“未完成的测试”一章)。
PHPUnit可以区分失败和错误。一个失败是PHPUnit的断言违例,错误是一个意料外的异常或一个PHP错误。有时候这种差别是有用的,因为错误相比失败更容易修正。如果你有一大串问题列表,最好先解决所有错误,然后看看有没有失败遗留下来。
让我们看看如下一些代码命令行测试工具的选项:
phpunit --help PHPUnit 2.3.0 by Sebastian Bergmann.
Usage: phpunit [switches] UnitTest [UnitTest.php] --coverage-data <file> Write code-coverage data in raw format to file. --coverage-html <file> Write code-coverage data in HTML format to file. --coverage-text <file> Write code-coverage data in text format to file. --testdox-html <file> Write agile documentation in HTML format to file. --testdox-text <file> Write agile documentation in Text format to file. --log-xml <file> Log test progress in XML format to file. --loader <loader> TestSuiteLoader implementation to use. --skeleton Generate skeleton UnitTest class for Unit in Unit.php. --wait Waits for a keystroke after each test. --help Prints this usage information. --version Prints the version and exits.
phpunit UnitTest
运行类UnitTest提供的测试,该类应该定义在源文件UnitTest.php中。
类UnitTest必须继承PHPUnit2_Framework_TestCase类,或是提供了公有静态方法suite,并返回PHPUnit2_ Framework_Test对象的类(例如,类PHPUnit2_Framework_TestSuite的一个实例)
phpunit UnitTest UnitTest.php
运行类UnitTest提供的测试,该类要定义在命令指定的源文件(UnitTest.php)中。
--coverage-data, --coverage-html, and --coverage-text
控制运行测试的代码覆盖信息的分析和集合(参见本书后代码覆 [1] [2] [3] 下一页 |