Nerdy tidbits from my life as a software engineer

Friday, December 19, 2008

Mock State Machine Visualizer

I was debugging a unit test yesterday that was using my mock framework, when it occurred to me that it would be a lot easier to figure out where I was failing if could somehow visualize the state machine that my code was walking through.  Currently there’s no easy way to do this: you have to step through your code, find the place where you get an expectation violation, and then backtrack to your recording and determine where things don’t match up.  This is one of the big rubs against record / replay semantics, and understandably so.  But I am generally a believer in using ordered recordings, so it would be nice if there was a way to make it easier to compare an expected sequence of calls to the actual sequence of calls - visually.

So now I’m wondering, what is the best way to do that?  Throwing up a dialog on a failed call to Validate is probably a bad idea.  Unit Tests should never throw up modal windows.  Maybe I could write a log somewhere to disk which could then be loaded into a UI and seen visually?  That seems like an easy way to go.  I was thinking simple html would probably be an easy way to do this.  What would be really nice, of course, is if I could somehow integrate this with Visual Studio…but I don’t see myself having the time for that.

I want something that almost looks like a file diff.  The left side has expected calls, and the right side has actual calls.  Indentations can signal the bounds of nested ordered / unordered blocks.  Clicking on a line gives you the details about that comparison (such as whether the arguments were ignored, etc.).  It can’t be too hard to come up with something, don’t you think?

0 comments: