PHP testing is necessary. How do we do it?

Source: Internet
Author: User
Example ~~ PHP testing is necessary. How do we do it? How to standardize your own tests and test what should you pay attention? Example ~~ PHP testing is necessary. How do we do it?
How to standardize your own tests and test what should you pay attention?

Reply content:

Example ~~ PHP testing is necessary. How do we do it?
How to standardize your own tests and test what should you pay attention?

It mainly depends on how the framework guides the test.

Codeigniter uses its own class library to perform simple assertion tests. The test results are directly output to the page or saved to the file. Relatively original and manual.

Yii framework uses PHPUnit as the test class library, and Selenium is also used to simulate formal operation scenarios to test the operation results under a specific browser. (The use of Selenium is a relatively abusive task, which is equivalent to simulating the user's operations on the browser with code and then asserted the expected results)

Laravel uses PHPUnit as the test class library and focuses on the business logic behind the test. However, in the front-end test, Laravel mainly makes some simple assertions about the Html page content generated.

I know that the test class library has SimpleTest in addition to PHPUnit, but I have never used or understood it.

The Code test coverage should be around 80%, and there is no need to pursue 100%. After all, the demand is dynamic.

The unit test can be done. It is difficult to perform a single test based on the written code and arbitrary code. Therefore, the first task is to compile the code that can be tested, therefore, we should consider how to test it during development. If we can follow the test-driven development and write a single test before coding, it would be better;

The second task is to write a single test. Piling is often troublesome, but the larger the system, the more external components and systems it depends on, and it cannot be tested without piling. Currently, phpunit supports piling.

Third, how can I test the code of an old project that is written at will without encapsulation, procedural, or even breadcrumb? All I can think of is either refactoring the code or having to do a lot of piling work; even so, there is no guarantee that the code can be tested separately.

In the past, I used thinkphp to write a program, and then I wanted to perform a unit test. Then I didn't have.

Generally, the basic process is repeated and tested. Generally, the framework has a debugging mode and multiple debugging is enabled ~

When you are not busy, unit testing and restTest are used together. When you are busy, just do restTest.
I hope the test will not be detailed.
RestTest is to use php to write a rest client that is closely related to the project, and then use the HTTP server that comes with php to start the project on the server (note that the test library is selected ), then use unittest to run scripts to access the rest interfaces one by one. Errors.

Unit test, PHPUnit

Create a hook, hand-Write the test code, and view the result.

There are very few tests. Generally, they are compiled and can be done without any problems.

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.