A probe into PHP unit testing: phpunit_php Tutorial

Source: Internet
Author: User
Do you encounter the following in the process of program development: When you take a long time to develop a PHP application, you think it should be done, but in debugging, always constantly find bugs, and most of all, these bugs are recurring, you may find that there is a link between these bugs, But it's always a problem to be found.

When you meet all of these frustrating situations, you will be able to think of a better way to solve it. Of course it is! This is the use of unit tests. Unit testing not only solves the headache problem to a certain extent, but also makes the code easier to maintain, and allows you to refactor the code more easily.

Once you have written the unit test case, when you need to modify your code, the thing you have to do is rerun your unit test case and observe whether the unit test cases pass, if passed, prove the code is OK.

People tend to say, "since unit tests are so good, why are so many people still reluctant to write unit tests?" There are several interpretations of this error:

1, think writing unit test is too waste of time. While many IDE tools now have a framework for writing unit tests, it's up to developers to write code for unit tests. Just like many of the best practices in development, doing the right thing in the right way can save a lot of time for development. Whenever new features are added, you may be able to access your Web page to click on manual tests, while running a well-established unit test case is faster than testing by hand.

2, think that since the code can run, no need to write unit test. But assuming that there are new members in the team, if there are no good unit test cases, the new members are likely to arbitrarily encode without considering the consequences. If you have well-written unit tests, you will be able to minimize bugs if you perform various tests while the program is running.

3, think writing unit test code is dull. The programmer's instinct is to solve the problem, and many programmers think it would be tedious to write unit test code when working on a tense coding. But you know, if you can write unit tests at an early stage to find as many errors in the code as possible, then save time and reduce errors, why not?

start a hands -on installation PHPUnit

This article will introduce the Unit Test tool in PHP phpunit (

http://www.bkjia.com/PHPjc/445847.html www.bkjia.com true http://www.bkjia.com/PHPjc/445847.html techarticle Do you encounter the following in the process of program development: When you spend a long time developing a PHP application, you think it should be done, but in debugging, always ...

  • 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.