Test Infected

July 3, 2005

After a month or so of driving code with tests I can say I'm officially "test infected". I completed my little PHP web services project, also it wasn't just fiction it was for a real client. I can truthfully say I didn't write a single line of code without first writing a failing test. I took small steps at times to work my way through some implementation issues but now that it's ready to release I'm quite pleased with the design and the code that came out of it. Every single line of code is accounted for, if I comment out any line in my program, at least one test will fail.

I had to use MockObject support to mimic NuSoap's web services functionality, which led to pretty loosely coupled components, which wouldn't have been the way I designed the project had I not used TDD.

Most people seem to be under the impression unit testing only works or is only needed for large projects. Well my project was pretty small (under 500 lines of PHP total) however it had high business value. It is a web services project that will be expanded in the future and will be dealing with millions of dollars worth of data. So from my view Test Driven Development can be applied for any size project if you will be adding on to it in the future or it has a high business value. I could at any point implement a new feature without fear of breaking something else down the road. If I realize my design sucks next year, I can refactor to a better design while the tests guide me to make sure I'm on the right track.

Special thanks to Marcus Baker, Jason Sweat and McGruff for the tips that helped me steer smoothly along the trail.

Comments

RSS feed for comments on this post.

  1. Eddie Peloke says:
    July 4, 2005 @ 11:31 — Reply

    I had the bad habit or writing my tests after my code (that is if I even wrote the tests at all) but I was just working on some new functionality and did the tests and code at the same time and really liked it. Constantly writing test code, writing running code and running the tests help me focus on small details and not wait until the entire class is done before I see major flaws. Plus, as you stated, I can refactor the code without worry as my tests will catch me if I mess it up. I am working now to get Rephlux up and running to see how well it handles 'continuous integration'.

  2. Jim says:
    July 5, 2005 @ 12:30 — Reply

    hey Eddie, do you feel more comfortable now doing test driven development? I'm curious to see how well it does over time for the stability of a project.

  3. Eddie Peloke says:
    July 5, 2005 @ 17:38 — Reply

    I am more comfortable with it now and feel the code is stronger because of it. The trick for me will be to realize that things will take a little longer now...at least up front. When I was given the assignment for this small project, I initially thought...that will just take a few days or so but then once I decided to do it the TDD way, it has taken a bit longer. I know it is all worth it and will greatly save time in future testing and refactoring...I just have to learn to adjust my personal time lines so I don't feel like I am behind.

  4. Louis Vuitton handbags says:
    June 16, 2010 @ 01:45 — Reply

    Comment pending moderation

Leave a Comment

Line and paragraph breaks automatic, HTML allowed: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <code> <em> <i> <strike> <strong>

Comments disabled due to spammers being losers that lead sad lives.