I had a fun day today at Glasgow Caledonian University. I’m midway through the a series of 10 lectures on Agile Software Development to 4th year Software Engineering students.
Todays 2 lectures were on XP and TDD.
Now, I really wanted to demonstrate TDD rather than to just talk about it, but I don’t have any recent coding experience. I don’t have an IDE either. I don’t have java or any xUnit setup.
So I improvised.
I used Excel to build a Roman numerals function in VBA. I used Excel itself to hold my test data (I’ve shown a snippet next, with the PASS and FAIL highlighted in Red and Green using conditional formatting) and I built the function up from scratch using my understanding of TDD (write a test, run it, fix it, refactor, etc).

Wow! It was an exhilarating experience. I haven’t coded in over half-dozen years and I don’t know bugger all about VBA but I was able (after a quick practice at the weekend) to build the function from scratch, complete with tests. And, boy do the tests help. Wow, what a learning experience.
Here’s the finished code, which may or may not be a bit ugly – I don’t know – but my tests all passed.
Public Function d2r(i As Integer)
d2r = m(i, "c", 100) + m(i, "xc", 90) + m(i, "l", 50) + _
m(i, "xl", 40) + m(i, "x", 10) + _
m(i, "ix", 9) + m(i, "v", 5) + _
m(i, "iv", 4) + m(i, "i", 1)
End FunctionPublic Function m(ByRef i, roman, dec) As String
Dim st As String
st = ""While i >= dec
st = st + roman
i = i - dec
Wendm = st
End Function
Anyway, I’m sharing this for two reasons.
- First, if you’ve never done TDD because you feel like a techie dinosaur then please give it a go using excel. I did it in front of 25 really bright young things and survived. In fact, although I was nervous to start with, after a while – as I built up my safety-net of tests – I soon felt like I could fly. In fact, it was a joy.
- Second, if you want to convince a manager about the joys of TDD then sit them down at Excel – it is already on their PC and it’s quite possible that they’ve already got some familiarity with VBA when they’ve tinkered with writing macros – and follow my example. Try it at home first though … there are a few little Excel things you need to figure out so you don’t look too dopey.
What a blast!
