上面的只是一个简单的加法的例子,为此,我们使用Annotations去编写一个单元测试,在上两篇文章中,我们采用的是手工编写单元测试的方法,而本文中,将介绍使用phpunit命令行的方法,自动生成单元测试的框架,方法如下:
首先把上面的类保存为MyMathClass.php,然后在命令行下运行如下命令:
phpunit –skeleton-test MyMathClass
这时phpunit会自动生成如下的框架单元测试代码:
<?php
require_once'/path/to/MyMathClass.php';
/**
* Test class for MyMathClass.
* Generated by PHPUnit on 2011-02-07 at 12:22:07.
*/
class MyMathClassTest extends PHPUnit_Framework_TestCase
{
/**
* @var MyMathClass
*/
protected$object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protectedfunction setUp()
{
$this->object=new MyMathClass;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protectedfunction tearDown()
{
}
/**
* @todo Implement testAddValues().
*/
publicfunction testAddValues()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}
?>