16:45 2015/12/8
PHPUnit Test Learning 1: A simple summary of useful things a little introduction to understanding
For specific introductory installation and introductory practices, please refer to the recommended blog or other online blog
Recommended blog, I feel that these several blog writing is very good, although one and two can be combined, not much content
And it's easier for beginners to bring learning confidence:
Installation recommendations refer to my other installation blog, because I failed in this way, the article mentions the net
The cause of the failure, I showed that the installation of a path does not seem to be maintained, the URL has not been saved
In the (so I do not know whether it is the network reason or the real path does not exist) (PHP Tutorial: PHPUnit Learning
Notes (i) PHPUnit introduction and Installation: http://be-evil.org/phpunit-study-note-
introduction-and-install.html)
PHP Tutorial: PHPUnit Study Notes (ii) PHPUNIT basic usage: http://be-evil.org/phpunit-
Study-note-basic-use.html
Phase three, four at the bottom of the stage two article, there are recommended links, please go to learn
PHPUnit can implement the dependency of the test method
Class Arraytest extends phpunit_framework_testcase inherit from
Phpunit_framework_testcase, further implementation of module testing
@depends: dependencies are defined by commenting @depends, if a test method relies on a method that tests no
PHPUnit will automatically skip all subsequent dependency tests.
@dataProvider: The Dataprovider label gives it the method name that provides the data, and after the definition phpunit will
The data returned by the data provider method is automatically passed to the test method in turn.
There is an example of the same test content implemented in the previous example, but the data provider returns
is an iterator object instead of an array (that is, the data within the object provides a way to return a new pair
Like---is the object of this class)
Check for exceptions: PHPUnit, we have 3 ways to check if an exception is thrown
@expectedException: Method One: Annotation method, using @expectedexception to calibrate expected anomalies
$this->setexpectedexception: Method Two: Setting method, using $this-
>setexpectedexception to set expected exceptions
Try Catch + Fail: Method Three: Try Catch + Fail method
Sometimes our code will run with PHP errors, such as divide 0, file does not exist, etc.
PHPUnit, it will automatically convert the error to an exception phpunit_framework_error and throw it, we just need
Set the fetch exception in the test method:
Instance:
/**
* @expectedException Phpunit_framework_error//expect
Phpunit_framework_error of the exception
*/
function Test () {...}
Assertion (assertions) is a series of methods provided by PHPUnit to test the results of a program execution. In layman's words, it
Is the value that asserts that the execution program results are what we expect
Assertarrayhaskey (mixed $key, array $array [, String $message = '])
The assertion array $array contains the index $key, $message the error message for the custom output, and the
PHPUnit Test Learning 1: A simple summary of useful things a little introduction to understanding