Instant Replay
I’m wrestling in my head at the moment with a dilemma. You see I’ve become a firm believer in automated unit testing as a part of a quality development effort but I’ve run up against a situation that seems to preclude the very thing I’ve come to believe in.
I wasn’t always a believer. I remember I started at eBusiness Interactive (then Cortex eBusiness now Cenqua) with really no idea how to develop software but some idea of Java and EJB’s and there was this guy sitting next to me who used to do strange things with something called JUnit. Over time I came to appreciate his quiet persistence and the company did too so by the time I moved on I had become a convert.
Fast forward to today where the code base I find myself working with has some unique characteristics that make it hard to unit test. Firstly there are no automated unit tests for this code, it’s a legacy system that is being maintained and enhanced. Secondly the methods in the code tend to take large objects as parameters and then extract complex data structures from them. The standard approach to this sort of thing is to use mocks but the data is such that the mocks would contain other mocks which would contain other mocks… you get the picture. Constructing all of those mocks and getting the data right would be a time consuming and error prone process which would take a long time to get ROI (the system is already in production) and hence is unlikely to be adopted.
Testing now is performed by firing up all of the components together and then applying external stimuli manually to generate the right inter component messages.
My thinking is that we need a new type of test tool to help construct those mock objects. The tool I am thinking of is a cross between two types of existing tools: record and playback test tools and code coverage tools. Code coverage tools are built to register when methods are called in code under test. What I am proposing is a tool that records not only what methods are called but in which sequence and with what parameters. This information could then be used to generate the appropriate code to create the mock objects. This code in turn could be modified to generate the appropriate unit tests. It would be a better starting point than nothing certainly.
Does something like this exist already? I can’t believe that noone has thought of it.






















