Sunday, September 21, 2008

Another Example for PHP Unit test Using PEAR

//ini_set('include_path','.:/root/PEAR'); Don't forget to set include_path where PEAR is installed in php.ini file or in .htacess for Apache server or explicitly in your coding

require_once 'PHPUnit/Framework.php';
require_once "PHPUnit/Framework/TestSuite.php";
require_once "PHPUnit/TextUI/TestRunner.php";
class ArrayTest extends PHPUnit_Framework_TestCase
{
public function testNewArrayIsEmpty()
{
// Create the Array fixture.
$fixture = array();

// Assert that the size of the Array fixture is 0.
assertEquals(1, sizeof($fixture));
}
}

$suite = new PHPUnit_Framework_TestSuite();
$suite->addTest(new

ArrayTest('testNewArrayIsEmpty'));

PHPUnit_TextUI_TestRunner::run($suite);
?>

"FYI, you have to create your own test cases according to your code and you will use classes and methods provided by PEAR's PHPUnit Package."

No comments: