PHP Unit Test User manual

Source: Internet
Author: User

1Introduction to Unit testing1.1Unit Test

Unit tests: is to check and verify the smallest testable unit in the software. (single module, a process, a function, etc.)

1.2unit test scope and target

unit tests include the planning phase, the design phase, the implementation phase, and the execution phase. Starting with the detailed design, the main source code of each module is tested until the end of the unit phase. This is primarily a PHP unit test.

The goal of unit testing is to isolate the program parts and prove that the individual parts are correct. A unit test provides a rigorous written specification of code snippets that need to be met.

2Installation and use2.1Installing PHPUnit

1 , download PHPUnit wget in Linux Https://phar.phpunit.de/phpunit.phar

2 , add Execute permissions chmod +x Phpunit.phar

3 , change path mv Phpunit.phar/usr/local/bin/phpunit

4 , view phpunit version PHPUnit--version


2.2Use

1, if you have detailed design documents, first carefully read the detailed design documents; for the PHP code that needs to be tested , first static (see if you are writing, see if there is a logic error, see if there are any features that are not implemented, and so on). )

2, write the test script (take xxx.php as an example)

1 ) First, call the XXX configuration files and calling PHPunit


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/4F/wKiom1TPRjqhLg9tAAEwxO9w3Nw067.jpg "title=" 1.png " alt= "Wkiom1tprjqhlg9taaewxo9w3nw067.jpg"/>


2) then test the module load class

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/59/4C/wKioL1TPR6qSwztKAAC_2q_Z7Y4102.jpg "title=" 2.png " alt= "Wkiol1tpr6qswztkaac_2q_z7y4102.jpg"/>


3) Finally write the test case (according to PHP code, analysis, etc., pass in the correct parameters, error parameters, missing parameters, redundant parameters, path coverage, condition judgment, etc.)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/4C/wKioL1TPSD3QuApPAAHp8XgCcqg257.jpg "title=" 3.png " alt= "Wkiol1tpsd3quappaahp8xgccqg257.jpg"/>

3. Execution comparison Returns the result phpunitxxx.php

1) When the correct data is sent to the request, check whether the returned data is correct, whether it will be error, whether the data is inserted properly in the database, and whether the related database will work properly.

2) when the error data sends the request, see if the returned data is handled with exception, if there is an error, the data is abnormal, and so on.

3 ) found a bug, submitted a bug to the relevant development and urged to fix the bug, only to close the bug.


PHP Unit Test User manual

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.