很久之前就想写单元测试了,但一直懒,但后来项目文件越来越大
发现当初真不该偷懒,现在开个新项目,这会可不在偷这个懒了,真可谓后患无穷...
久了没写phpunit,发现生疏了,看过了一遍手册,http://www.phpunit.de/manual/3.7/en/index.html
写了点备份的笔记:
数据提供者
运行时观察者接口
实现该接口,用于运行时回调,可在配置中配置或直接实例添加
使用实例
/Files/liushannet/code.rar
命令参数说明:
--log-* 日志文件格式及保存到
--coverage-* 测试覆盖率及保存到
--testdox-* 测试dox及保存到
--filter 去除某些目录或文件
--testsuite 指定suite
--group 只执行指定组测试
--exclude-group 执行包该改组测试
--list-groups 列出所有组
--test-suffix 测试文件后缀
--bootstrap 测试前先执行的文件 (部署环境独立)
--c 配置文件 (详细介绍:http://www.phpunit.de/manual/current/en/appendixes.configuration.html)
--include-path 运行前先引入文件
配置 phpunit.xml 实现自动化测试
This is an example phpunit.xml file to get you started
Copy it to a directory, update the relative paths and rename to phpunit.xml
Then to run tests cd into it's directory and just run
phpunit
(it'll automatically use any phpunit.xml file in the current directory)
Any options you specify when calling phpunit will override the ones in here
-->
< phpunit colors ="false" bootstrap ="modules/unittest/bootstrap.php" >
<!-- 测试列表 -->
< testsuites >
< testsuite name ="Kohana Tests" >
<!-- directory suffix="Test.php">/path/to/files</directory -->
< file >modules/unittest/tests.php </ file >
</ testsuite >
</ testsuites >
<!-- 执行的组 -->
< groups >
< include >
< group >kohana.image </ group >
</ include >
<!-- exclude>
<group>name</group>
</exclude -->
</ groups >
<!-- 日志记录 -->
< logging >
< log type ="coverage-html" target ="./report" charset ="UTF-8" />
< log type ="testdox-html" target ="report.html" />
</ logging >
<!-- 环境变量设置 -->
<!-- php>
<includePath>.</includePath>
<ini name="foo" value="bar"/>
<const name="foo" value="bar"/>
<var name="foo" value="bar"/>
<env name="foo" value="bar"/>
<post name="foo" value="bar"/>
<get name="foo" value="bar"/>
<cookie name="foo" value="bar"/>
<server name="foo" value="bar"/>
<files name="foo" value="bar"/>
<request name="foo" value="bar"/>
</php -->
<!-- 代码覆盖的黑白名单 -->
<!-- filter>
<blacklist>
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
<exclude>
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
</exclude>
</blacklist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
<exclude>
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
</exclude>
</whitelist>
</filter -->
<!-- 添加运行时观察者实例,实现:PHPUnit_Framework_TestListener -->
<!-- listeners>
<listener class="MyListener" file="/optional/path/to/MyListener.php">
<arguments>
<array>
<element key="0">
<string>Sebastian</string>
</element>
</array>
<integer>22</integer>
<string>April</string>
<double>19.78</double>
<null/>
<object class="stdClass"/>
</arguments>
</listener>
</listeners -->
</ phpunit >
加上自动部署:
完美了.