天天看點

phpunit測試成功 phpunit測試實踐代碼

16:12 2015/12/8

phpunit測試成功,代碼寫在www目錄下,以類名命名代碼檔案,我的檔案名為

ArrayTest.php,類名為ArrayTest,内部寫了簡單的測試代碼:

<?php

// require_once 'PHPUnit/Autoload.php';

// require_once 'ArrayTeller.class.php';

// require_once 'PHPUnit/Framework.php';

class ArrayTest extends PHPUnit_Framework_TestCase

{

public function testNewArrayIsEmpty()

{

// 建立數組fixture。

$fixture = array();

// 斷言數組fixture的尺寸是0。

$this->assertEquals(0, sizeof($fixture));

}

/**

*定義test标簽聲明該方法的測試方法

*@test

*/

public function indexEquals()

$stack = array(1, 2, 3);

$this->assertEquals(2, $stack[1]);

}

,然後

cmd的DOS視窗進入www目錄下,

執行phpunit ArrayTest.php,回車執行即可

終于成功了