Unit Testing….NUnit, PHPUnit, Smarty..and stuff
October 17, 2006My personal project has been coming along quite nicely recently, I have been retooling my PHP framework to be able to utilize the Smarty templating engine and it has been going really well. I rewrite several pages using smarty and i am terribly enthused about how clean things have become. My framework went to great efforts to keep things as clean as possible but this makes the whole system significantly cleaner. Very VERY nice.
I have also been spending some time fiddling around with unit testing in both php and .net using PHPUnit and NUnit respectively.
In the .NET project i’ve been working on I started writing unit tests alongside the creation of the application. This has already saved me quite a bit of time in terms of changes in various objects/classes breaking things in unexpected ways. I am almost sold on the whole concept, my initial thoughts around this were that the unit tests would be instructive for the initial development but their benefits would not be realized until the client requested new features to be implemented, at this point I could make the changes and then ensure that the application had been broken because of these changes. However, there have been many times that I have found the unit tests very useful during development, whether it is catching coding errors, or providing a convenient way to run a bit of code and see how it behaves.
This has carried over to the personal project and efforts to get PHPUnit setup and tests written for all of my business objects. Work is going a little slower on this mostly due to challenges I had with Centos but I have done a few small tests and everything seems to be in working order. I am probably going to write tests for all of the new classes, and then build the tests for the existing objects when I touch them.
One thing that has worked extremely well for me is to start each session off by writing a couple of unit tests, or going through the testing code and seeing if there’s any way I can test something better. It helps get me into the groove of writing code, and gets my head in the project, but it doesn’t just dump me right into the middle of the business logic. I can sorta ease my way into it. Write a test..did it pass? Cool..or damn! why not?. I’m a big believer in inertia when it comes to development, you’ve gotta crank through a few things, get the mind, and fingers, warmed up then start to tackle some of the bigger things.





