When I make a web app I test my work on the browser to see if I receive any errors and fix them. I have made complex applications and testing this way has been easy and fast. I have watched many videos on youtube regarding phpunit and cannot find a purpose for it. Why is this library useful? Is phpunit more for php framworks like cakephp or zend? I dont use any framework just core php. Would or can phpunit be useful for me? If yes, how?

There is also xdebug but I'm not sure if it relates.

  • 5
    How long does it take for you to recheck a complex application in every corner? – user1249 Oct 25 '11 at 9:50
  • @user1249, phpUnit is still unable to do automated functional testing. It only does automated unit testing. – Pacerier Jul 30 '15 at 8:07

Would or can phpunit be useful for me? If yes, how?

Yes, definitely.

phpunit belongs to the family of xUnit test libraries. You use these libraries to create automatically executable tests which verify your application's behavior. This is important to ensure, among others, that your changes don't break existing functionality.

Listing all reasons for automated testing, the various kinds and technologies would be too much. Check out the following links to read about:


Let's say that you wanted to manually test your application every time that you deployed it. How would you go about doing that?

Well, to start with, you might make a list of all the things you want to test so you wouldn't forget to test something later on. Then you would probably write the steps for each test to make sure that you did them the same way each time. If you didn't make sure the testing process you used was consistent, your results wouldn't be consistent.

So, now that you have the list of tests you need to perform, you would open your browser, read the first test's steps, perform them, and make a note of the result. You would repeat this process for each test in your list.

The number of tests you perform would continue to grow as your application grows and as you find new bugs. You would, of course, be limited to performing these tests at human speed, making them rather slow.

The irony here is that in mechanically stepping through a list of operations, you are computing. You're just doing it way more slowly than, say, a computer would.

This, among many other good reasons, is why we write unit tests: they let the computer do the computing so you don't have to.

I can run a comprehensive unit test suite fast enough to use it frequently during development, not just once a week before deploying. This lets me detect errors more quickly, saving me time and money.

I can even write tests that predict the behavior of the system and then write that behavior (which I already know is correct because I just tested it), a process known as Test Driven Development.


Manual testing (i.e. clicking on the application in the browser) is actually called functional testing. Functional testing and unit testing are two different methods used in QA. Why do you think you can't use them both?

Unit testing is used to test if your code is working as expected (e.g. if your web service handles error appropriately or if it returns the results as expected).

When you click on your application you are testing the functionality of your application.

Would or can phpunit be useful for me? If yes, how?

Unit testing has many benefits - it can be very useful tool when refactoring because you can confirm that the code is working as expected. Also, when someone is reading your code it can be very helpful to see the intended use of the code in the unit tests.

  • Unit tests also test behavior. You are creating a false dichotomy. – Rein Henrichs Oct 25 '11 at 16:21
  • @ReinHenrichs, Functional testing is done by Selenium, not PHPUnit. – Pacerier Jul 30 '15 at 9:49


Yes. Absolutely yes.

Actually, that needs qualification. Unit testing frameworks like PHPunit are useful if you are writing and maintaining an application that other people are expected to use.

The reasons why unit testing is useful include

  • Regression testing for specific bugs that you've exposed, and

  • Running unit tests are much much faster than manual testing, and so can be much more thorough.

In the company I work for, we write unit tests before we write the code that passes them. This helps us produce sane, testable designs (because we have to think about what we will write before we do it!) and it provides an easy way of asserting that our code meets the requirements of the user.

Not the answer you're looking for? Browse other questions tagged or ask your own question.