PHP Unit Testing Tool: PHPUNIT preliminary _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP Unit testing tool: a preliminary study of PHPUNIT. Do you encounter the following situations during the process of program development: After you have spent a long time developing an application, you think it should be a success. Unfortunately, when debugging, I don't know whether you have encountered the following situations in the process of program development: After you have spent a long time developing an application, you think it should be a success. Unfortunately, when debugging, bugs are constantly discovered, and the most terrible thing is that these bugs are repeated. you may find that these bugs are associated, but you can't find the problem.

When you encounter these situations that make you frustrated, you will definitely think about a better solution? Of course there are some solutions! This is the unit test. Unit testing not only solves the above headaches to a certain extent, but also makes the code easy to maintain and allows you to refactor the code more.

Once you write unit test cases, when you need to modify your code, you have to re-run your unit test cases and observe whether these unit test cases can pass, if the code passes, the code is okay.

People often say: Since unit tests are so good, why are so many people reluctant to write unit tests? There are several misunderstandings:

1. it is too time-consuming to write unit tests. Although many IDE tools have established a framework for writing unit tests, developers still need to write some unit test code. Like many best practices in development, doing the right thing in the right way will save a lot of time for development. When new features are added, you may access your web page and click manually to test the unit test cases, which is faster than manually testing the unit test cases.

2. since the code can run, you do not need to write unit tests. However, if there are new members in the team and there are no good unit test cases, it is very likely that the new members will code at will without considering the consequences. If you have a well-written unit test and perform various tests while running the program, you can avoid bugs to the maximum extent possible.

3. think that unit test code writing is boring. Programmers solve the problem by nature. many programmers think that unit test code writing is boring during intense coding. However, if you can discover as many errors as possible in the code by writing unit tests at an early stage, it will save time and reduce the number of errors. why not?

  Start to install phpunit

This article will introduce php's unit testing tool phpunit (http://phpunit.de/), and explain how to use phpunit in practical work through practical examples. First, you can install phpunit using pear in php:

Pear channel-discover pear.phpunit.de
Pear channel-discover components. ez. no
Pear channel-discover pear.symfony-project.com

...

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.