Skip to main content

Why use phpunit when traditional manual testing can be used [Resolved]

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.

Question Credit: Sarmen B.
Question Reference
Asked March 19, 2018
Posted Under: Programming
5 Answers

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:

credit: BenR
Answered March 19, 2018

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.

credit: Rein Henrichs
Answered March 19, 2018


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.

credit: Edward Bowles
Answered March 19, 2018

Hello i have already advanced to using framework. I use codeigniter with wired designz. I want to know if it requires unit testing too. And what scenario. And if theres any resource out there that can explain more on hmvc codeigniter unit testing.

credit: Sylvester hillary
Answered March 19, 2018
Your Answer