Testing, testing – beginning test driving development with PHPUnit

I have been working on a project which has gone slightly wrong for a variety of reasons. Most of which I am not going to go into here.

However one of them was a lack of testing. Not full system testing but the less glamorous and more (let’s be honest) tedious unit testing. I have ventured into testing before but not on an enterprise scale. Previous companies have not seen the benefit in spending time in creating tests and running them.

In a sense I fell into it quite by accident. I was running some manual tests for another project, following a set of use cases and test plans. All went well if slowly. Having got in early, I spent some time using the Selenium IDE in Firefox using the WYSIWYG editor in an attempt to quickly put some tests together. Having run the tests, the time taken to do them were cut down significantly but more importantly, they can be run again and again in the same way. Unless altered. Then they can be run again and repeated. Yes, setting up tests takes time but in the long run appears worth it in terms of confidence.

The confidence comes from being able to repeat things and to be able to identify either code or user story issues. If new code comes in, the code can be run and regression tests performed.

That is running tests at the end though. What about developing? That’s where Test Driven Development or TDD (Wikipedia, Agile Data on TDD, ) comes in. Or where I hope and strongly believe it will.

I am not going to go into what TDD is but drawing on current experience, it will allow me to have a greater confidence in the built code. In the long run, spending some spare time getting into writing tests and then building code around them should allow me to refactor the code and remove its issues.

Moving on though, I can use it to make sure that bad code does not creep back in. Since we use PHP at work, I have been using PHPUnit as the best framework. Having dipped in and out of PHPUnit over the last couple of years, I needed a quick reminder about some of its features and how to set it up to read existing classes which is what this sitepoint article gives.

Is this where it ends? No.

The next jump to make is to get the Jenkins Continuous Integration tool to run the tests that I write. Automatically. Whilst writing the tests and then code offers confidence that the while thing is going to do what I think it is doing, I would really like to not be continually running the tests. I have installed the Jenkins tool on to Ubuntu 10.10 (though upgraded to 11.04 recently) and once the first tests are written, then I will set up a project in Jenkins to run it. That is another post for another day.

So where does this leave me? In the first place, I am playing a certain amount of catch up to build a testing skeleton. It will have holes but the coverage can be extended and I get into better practices with regards development.

More importantly, the code that I write can be released with a certain amount of confidence and built on or against with that confidence.


Beginning DisplaySuite on Drupal

New project, new thoughts. We have been discussing the ways of displaying material to the end user in Drupal 7. The options that we had were Panels and Display Suite. I’ve just been playing with Display Suite which I have heard really good things about but never got around to using. Ivan Zugec’s tutorial (part


Exploring realtime presence

I went down to the London Realtime event event today. In part, it was to  learn more about realtime programming and partially because RabbitMQ were going to be there and it would be a good chance to talk to somebody about the message queueing (MQ). I did manage to bend somebody’s ear (sorry if I


Beginning using Drupal and TokBox

I’ve been playing around with TokBox and the Drupal plugin (7 only) for a project to see where it can go. TokBox is a video API which can be used to set up video sessions, say to publish only like a lecture, or to have a conversation and to link people together. Reading the University


Weeknotes: Testing and documentation

It has been a slightly quiet week but one in which I have been working on the quieter parts of development – testing and documentation. I was helping out some colleagues by testing some existing code this week. not because I do not have any thing to do but because they are woking on something


Trying to geolocate a part of Charles Dickens

I have been working at a snail’s pace on some geolocation queries on some locations which are associated with Charles Dickens. Using Python’s NLTK library, I managed to extract around 60 distinct locations from his novel, Bleak House. A bit of human editing has tidied this up for me but it looks useful. Having popped


Weeknotes: Open Correspondence and TextCamp

It has been a while since I’ve written a weeknote. Must get back into the habit. Open Correspondence Development on the Open Correspondence project has been slow to stalled for a while. I have been doing bits and pieces but sitting down with Mark McGillivray of Cottage Labs and the Open Knowledge Foundation, brought some


Going to the other place – or a weekend at DrupalScienceCamp

I went to the Drupal ScienceCamp  for the weekend to learn more about Drupal and also how one runs a DrupalCamp, since we are thinking of doing one in Oxford. Having come across on the Friday and met some people, the weekend really started on the Saturday, run by some of the team behind the


Writing specs – a first starting point

Our team have started on Scrum to move forward with our projects. So far, so staggering steps but, hey, we are new to it. We will learn by falling / failing and then learning from where we went wrong and fixing it. One of the things that I have been looking at, partially because, as


Bridging message queues in STOMP and AMQP

A recent work project has been working with messaging queues and exploring how they work. One of the issues has been how to get systems running different systems to talk to each other. One system uses ActiveMQ and another runs RabbitMQ which has led to some interest in how to effectively bridge the systems into