Repository navigation
Unit testing in the real world
We now take for granted testing as something that's integral to the development cycle and indeed some testing has always been, but unit testing is relatively new to the whole process. If you have ever worked on legacy systems you'll probably find the low levels of coverage shocking, take care in those circumstances because the code will be brittle as anything.
Here I talk about how the testing approaches I have learned developing software can carry through into the real world of day-to-day living, away from software and computers. The analogy of building houses is often used to describe software development, can the reverse also be true? let's see.
After a particularly cold winter we decided to upgrade our heating system, everything had been fine up to last year but the cold spell we went through was enough to force us to consider alternatives and finally settle on central heating, yeah I know it's been around since the 30s, or the romans if you want to take their version into account.
To begin with we researched the alternatives of all components we needed: radiators, TVRs, boilers, pumps, control systems, plumbing approaches, circuit design, zoned heating systems. All in all I probably spent as much time going through this as I would while selecting the libraries I'm going to use on a new project.
As in any design there are also constraints, BTUs, building regulations, the type of radiator valves, radiator placement, insulation requirements.
BTW, I now know way too much about TVRs, if you see me you can ask me about them, but I probably won't talk about them as it's not the most thrilling subject I have ever had to deal with.
OK, I skipped the development stage as at that point the analogy doesn't really work, anyway, the build was simply the task of:
- Lifting floorboards (which were screwed in from previous jobs so it wasn't as painful as it could have been).
- Cutting bits of plasterboard out of the wall -as little as I could get away with as I wanted to avoid having to put the walls back up and re-plastering.
- Plumbing, lots and lots of plumbing running all over the house, the only room it doesn't touch is the study, I like it cooler in there.
So all-in-all a lot of heaving and pushing but that was one of the advantages of doing it ourselves, we could take our time and do it as we wanted it.
Funny, thinking about the fact that if I messed up I could end up with the living room ceiling collapsing and gallons of water staining every bit of furniture and freshly painted walls, really pushed home the importance of testing every component and stage thoroughly in a methodical fashion. It was then that I really understood the importance of testing.
I treated each radiator as the unit to be tested, it has a number of components: valves, compression joints, plumbing to the main circuit, any of these could fail and cause the dreaded failure (a flood, or at least a slight water stain).
In order to test a radiator I had to build a 'test harness', this consisted of a pressure gauge, some pipework, a bicycle pump and a some soapy water. Using this harness allowed me to pressure test each unit well beyond what the system would experience under load and narrow the risk of having to drain the system several times, thereby reducing the total amount of time and effort spent in getting the whole thing up and running. In all, the testing found five joints which leaked.
Once the unit testing had been signed off (I couldn't find any more leaks) it was time to move onto the integration testing round. I connected the downstairs circuit into the boiler and started filling it up with water; now I could have used air, but that volume of air compressed up to 3.5 bar could result in injury if an end cap flew out and shot out hitting you in the head (or at least a scratch on the wall).
It took a few rounds of topping up up to 1.5 bar and bleeding radiators every few minutes to get the initial test going, one leak showed up as a direct result of a mistake on my part, I ended up replacing a length of pipe with one that gave the joint a bit more elbow room. Later on, while bleeding another radiator I unscrewed the valve fully off. Damn it! Let's empty the whole system and start again. When the bottom circuit was complete the heating was run for a couple of hours.
Time to repeat the whole process after plugging the upstairs circuit in and refilling the system. Another leak, this was caused by a knackered blanking cap on a brand new radiator; it turned out this hadn't been tested (it wasn't on my checklist), so make sure you always get someone else to review your test scope, anyway that was replaced, the system refilled and it all looked OK.
The approach for this stage was easy, but nerve wracking: add more water, watch the pressure gauge and run upstairs, downstairs and into the crawl space checking every joint for any leaks.
Raise it up to 1 bar and leave it for an hour, more running up and down. Repeat several times increasing the load each time: 1.5 bar, 2 bar, 3 bar, 3.5 bar without turning the heating on, oops, as the day was almost done I left it at full load over night and checked the results in the morning.
First thing in the morning, coffee then more running around checking for any failures. No leaks!
Reset the system to normal operational load (drained some water off to get back down to 1.5 bar), add some inhibitor, then turn the heating on for a couple of hours. Once everything looked OK it was just a matter of going round a few times balancing the radiators.
It got cold last week so we turned on the heating on, hey it works!!
The central heating is the DR, we'll be mostly relying on the wood burner as it works out cheaper.
This experience proved to me the value of testing everything thoroughly before publication, I will certainly increase the range and type of tests I use as part of my normal development process and ensure I run it past a colleague to make sure the scope is adequate. I will also use that approach on anything else I can think of where it makes sense.