Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit tutorial? Or more general - unit testing tutorial worth recommending? [closed]

I'm looking for a tutorial which explains why and how to write useful unit tests. Specifically I'm interested in PHPUnit, however any more general might be a good one to explain that. Please note that I'm not looking for technical information on how to use PHPunit - rather the tutorial on the way of thinking!

like image 471
migajek Avatar asked Jul 24 '10 17:07

migajek


1 Answers

I do not know of a tutorial. But I can give you my views from what I have gathered over the years.

Writing UnitTests are meant to test the functionality of the application. Thus given this say you write a core class that has 3 functions, getData setData and displaydata (just thinking off the top of my head). You want to write a unit case that goes in set's a Data (you pass in good data and bad data because it is important to know that it errors properly). Then you check the setData, either via a DB call or with the same class using the getData, and you try and get the data with bad data, good data etc. Make sure this handles that properly. Then you write the display data and rinse and repeat.

Basically you want to test that the core class (or application classes) handles data properly (errors / good data etc). If all of the tests come out clean then you can move up and write a test for other classes that use that core class. But there is no point to moving on if your core class does not / has not pass tests or else debugging becomes a night mare. I have never really looked into PHP Unit test, I used to just write all mine given Use Case Scenarios (IE: How the functions would be used / implemented). This is a general way of thinking what to write up a test-case for.

Hope this helps.

like image 149
Jim Avatar answered Sep 30 '22 17:09

Jim