PHPUnit袖珍指南之命令行测试工具

皮肤科李医生

皮肤科李医生

2016-01-29 13:27

PHPUnit袖珍指南之命令行测试工具,PHPUnit袖珍指南之命令行测试工具

 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

  控制运行测试的代码覆盖信息的分析和集合(参见本书后代码覆盖分析一节)

--testdox-html and --testdox-text

  以HTML或普通文本格式生成运行测试的敏捷文档(参见本书后的“测试的其他用途”一章)

--log-xml

  生成运行测试的XML格式的日志文件。

  下一个例子显示为ArrayTest中的测试生成的XML日志文件。

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
 <testsuite name="ArrayTest" tests="2" failures="0" errors="0" time="0.020026">
 <testcase name="testNewArrayIsEmpty" class="ArrayTest" time="0.014449"/>
 <testcase name="testArrayContainsAnElement" class="ArrayTest" time="0.005577"/>
</testsuite>
</testsuites>
  下面的XML日志文件是为名为FailureErrorTest的测试类两个测试生成的,一个是testFailure,一个是testError。这显示了失败和错误是如何分别表示的。

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
 <testsuite name="FailureErrorTest" tests="2" failures="1" errors="1" time="0.013603">
 <testcase name="testFailure" class="FailureErrorTest" time="0.011872">
 <failure message="" type="PHPUnit2_Framework_AssertionFailedError"></failure>
</testcase>
<testcase name="testError" class="FailureErrorTest" time="0.001731">
 <error message="" type="Exception"></error>
</testcase>
</testsuite>
</testsuites>
--loader
  指定将要使用的测试套件加载器。

  标准测

展开更多 50%)
分享

猜你喜欢

PHPUnit袖珍指南之命令行测试工具

PHP
PHPUnit袖珍指南之命令行测试工具

Linux命令行中网速测试方法详解

电脑入门
Linux命令行中网速测试方法详解

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Delphi命令行参数

编程语言 网络编程
Delphi命令行参数

Linux命令行之逗趣的图文

服务器
Linux命令行之逗趣的图文

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

启动命令行选项

编程语言 网络编程
启动命令行选项

Linux系统命令行Find工具使用小技巧

Linux Linux命令 Linux安装 Linux编程 Linux桌面 Linux软件 Linux内核 Linux管理
Linux系统命令行Find工具使用小技巧

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

如何防止SWF文件被反编译

如何防止SWF文件被反编译

利用PHP+JavaScript打造AJAX搜索窗(4)

利用PHP+JavaScript打造AJAX搜索窗(4)
下拉加载更多内容 ↓