PHP testing is necessary, how do we do it?

Source: Internet
Author: User
Title ~~php test is necessary, how do we do it?
How to standardize their own testing and testing should pay attention to what?

Reply content:

Title ~~php test is necessary, how do we do it?
How to standardize their own testing and testing should pay attention to what?

The main view is how the framework guides the test.

CodeIgniter uses its own class library for simple assertion testing, and the test results are output directly to the page or saved to a file. Compared to the original manual.

The YII framework uses PHPUnit as the test class library, and the selenium is used to simulate the operation results under the specific browser for a formal operating scenario. (The use of selenium is a more masochistic thing, equivalent to using code to impersonate a user to assert the expected results after each action on the browser)

Laravel also uses PHPUnit as the test class library to test the latter business logic, but in the front-end test, it is primarily about the content of the generated HTML page to make some simple assertions.

I know that the test library has simpletest in addition to PHPUnit, but it has not been used and understood.

Code testing coverage of about 80% should also be almost, there is no need to pursue 100%. After all, demand is dynamic.

Unit testing can do, first rely on the code, write arbitrary code, it is difficult to do single measurement, so the first task is to write code that can be tested, so the development of the time to consider how to test, if you can follow the test-driven development, before the code to write a single measurement, that better;

The second task is to write a single test. Piling is often cumbersome, but the larger the system, the more dependent the external components and systems, the more it is not possible to test without piling. Currently PHPUnit has support for piling.

Third, if the old project, the code is free to write, the lack of encapsulation, procedural, and even the breadcrumb code, how to test? I can think of either refactoring the code or having to do a lot of piling work, and even so, there is no guarantee that the code will really be tested.

I used thinkphp to write a program, and then I wanted to do a unit test, and then I didn't.

The general basic process goes through the test. The general framework has debug mode, open multi-debug Debugging ~

When work is not busy, unit tests are done together with Resttest. When you are busy, do resttest on the line.
I hope the test will not be elaborate.
Resttest is to use PHP to write a close to the project and the rest client, and then use PHP's own httpserver to do the server startup project (pay attention to select the test Library), and then use the UnitTest run a script to access the rest interface. Judgment error and so on.

Unit Test, PHPUnit

Make a hook and then write the test code and see the results.

Rarely to do the test, the general situation is compiled, no problem on it.

  • Related Article

    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.