All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL,Server数据库和XML标识语言的集成_[SQL,Server教程]
VS2008的Linq,更新数据就那么费劲?_.net资料_编程技术
ASP.NET中广告控件AdRotator使用方法_[Asp.Net教程]
一个有关SQL Server连接的问题_[SQL Server教程]
用asp.net程序备份或还原SQLServer_[Asp.Net教程]
php上传获取文件相应参数-获取上传文件后缀名_php资料_编程技术
WCF分布式开发常见错误:-Unrecognized,attribute,’targetFramework’,(未识别的属性’targetFramework’,)_.net资料_编程技术
mysql,设置,log,保留天数_mssql学习_编程技术
XP下安装SQL2000企业版_[SQL,Server教程]
C#中的多媒体技术:文字处理
Reading number is top 10 pictures
男人帮杂志里的惹火性感美女2
From China fortress sora aoi1
The money of more than 100 countries and regions11
Gang rape
中国处女图鉴1
男人帮杂志里的惹火性感美女1
中国处女图鉴2
这才是真正的人体艺术1
职场回春术
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line
Download software ranking
Call Of Duty5
网页特效实例大全
双旗镇刀客A
linux安装大全
SP3 for SQL2000
Red cliff
The cock of the Grosvenor LTD handsome
I'm come from Beijing2
小黑猫大战两米大花蛇
Tram sex maniac 2 (H) rar bag6
归海一刀 published in(发表于) 2014/2/10 6:46:18 Edit(编辑)
PHPUnit袖珍指南之命令行测试工具_[PHP教程]

PHPUnit袖珍指南之命令行测试工具_[PHP教程]

PHPUnit袖珍指南之命令行测试工具_[PHP教程]

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

  指定将要使用的测试套件加载器。

  标准测试套件加载器会在当前工作目录和PHP的include_path configuration指令定义的路径中寻找源文件。按照PEAR的命名规则,形如Project_Package_Class的类名会映射到的源文件为Project/Package/Class.php。

  --skeleton

  为类Unit(在文件Unit.php中)生成一个名为UnitTest(在文件UnitTest.php中)的测试用例类的框架。对原始类的每个方法,在生成的测试用例类中提供了一个未完成的测试用例(见本书后的“未完成测试”部分)。

  下面的例子显示了如何为一个名为Sample的类生成一个测试类的框架。


phpunit --skeleton Sample
PHPUnit 2.3.0 by Sebastian Bergmann.
Wrote test class skeleton for Sample to
SampleTest.php.
phpunit SampleTest
PHPUnit 2.3.0 by Sebastian Bergmann.
I
Time: 0.007268
There was 1 incomplete test case:
1) testSampleMethod(SampleTest)
OK, but incomplete test cases!!!
Tests run: 1, incomplete test cases: 1.

  当你为现有代码书写测试时,你不得不重复很多相同的代码片断,如:


public function testSampleMethod( ) {}


  PHPUnit能帮助你分析现有代码,生成测试用例类的框架。

--wait

  每个测试结束时,等待一次击键。这很有用,特别是你在一个只有测试一直运行在打开的窗口中运行测试时。

  提示 当被测试代码中有PHP语法错误时,文本界面的测试会直接退出,不输出任何错误信息。标准的测试套件加载器会检查测试套件的源文件的PHP语法错误,但是,它不会检查测试套件包含的源文件的语法错误。PHPUnit的未来版本会用在砂箱中PHP解释器类解决这个问题。


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.