文件名称:phpunit-master测试单元库.zip
文件大小:440KB
文件格式:ZIP
更新时间:2022-07-31 05:01:05
类库下载-phpunit-master测试单元库
[php] view plain copy <?php class StackTest extends PHPUnit_Framework_TestCase { public function testEmpty() { $stack = array(); $this->assertEmpty($stack); return $stack; } /** * @depends testEmpty */ public function testPush(array $stack) { array_push($stack, 'foo'); $this->assertEquals('foo', $stack[count($stack)-1]); $this->assertNotEmpty($stack); return $stack; } /** * @depends testPush */ public function testPop(array $stack) { $this->assertEquals('foo', array_pop($stack)); $this->assertEmpty($stack); } } ?>1. 什么是单元测试?【百度百科】单元测试是对软件中的最小可测单元进行检查和验证。是开发者编写的一小段代码,用于检验被测代码的一个很小的、很明确的功能是否正确。2. 作用是什么?【废话】检查软件、程序的可行性,稳定性。通过单元测试能够避免在迭代、升级等过程中,引起重复的、多余的问题。避免在别人修改代码的时候,影响到你的逻辑3. 哪些程序需要写单元测试(PHP)?【理想】理想的单元测试应当覆盖程序中所有可能的路径,包括正确的和错误的路径,个单元测试通常覆盖一个函数或方法中的一个特定路径。【现实】model、helper、controller中的函数必须测试、路径覆盖到所有可能性