PHPUnit is an open-source software developed in PHP programming language and a unit testing framework. PHPUnit was created by SebastianBergmann and originated from the SUnit of KentBeck. It is one of the xUnit family frameworks. This article introduces
PHPUnit is an open-source software developed in PHP programming language and a unit testing framework. PHPUnit was created by Sebastian Bergmann and originated from Kent Beck's SUnit. It is one of the xUnit family frameworks. This article introduces
PHPUnit is a testing framework officially supported by zend. It ensures the foundation of project quality in high-quality unit tests, effectively reduces bugs and improves programs.
Install PHPUnit:
Under the php Directory:
The Code is as follows:
Pear channel-discover pear;
Pear install phpunit/PHPUnit
Add the php environment variable to the PATH environment variable in windows.
Easy to use:
The Code is as follows:
<? Php
Class StackTest extends PHPUnit_Framework_TestCase
{
Public function testArray ()
{
$ Stack = array ();
$ This-> assertEquals (0, count ($ stack ));
Array_push ($ stack, 'foo ');
$ This-> assertEquals ('foo', $ stack [count ($ stack)-1]);
$ This-> assertEquals (1, count ($ stack ));
$ This-> assertEquals ('foo', array_pop ($ stack ));
$ This-> assertEquals (0, count ($ stack ));
}
/**
* @ Test
*/
Public function Stringlen ()
{
$ Str = 'abc ';
$ This-> assertEquals (3, strlen ($ str ));
}
}
From the above, we can see the basic rules for compiling PHPUnit:
(1) Test the Class in ClassTest
(2) ClassTest inherits from PHPUnit_Framework_TestCase
(3) The test method is in the test * format. You can use @ test to mark it as a test method.
(4) assertEquals can be used to assert the actual and expected values.