views:

109

answers:

2

I'm maintaining a ~300K LOC C# legacy thick-client application with a Windows.Forms interface. The app is full of little bugs and quirks. For example, I recently discovered a bug where if a users edits and tabs (not clicks) through cells on a DataViewGrid, and leaves the a certain cell selected, the app gets an "Object reference not set to an instance of an object" exception. I discover (or get a bug report of) something new like this about every week or two. I've had enough, and was thinking of trying some sort of fuzz testing on the application to try to ferret out undiscovered issues.

If I roll-my-own fuzz testing, I'd assume I at least need to be able to generate test harnesses that run pieces of my app (main window, FormX, FormY, FormZ, ...) independently and try to inject events into them.

I was trying to look for tools suited for this, but so far have come up with nothing for Win Forms. (There seems to be no shortage of fuzz testing tools for web apps, however).

Any helpful ideas?

+1  A: 

I always like the idea of the Gremlins test tool, used on Palm handhelds. It generated random tap events to flush out UI programming bugs. You could do the same in your app, generating millions of mouse down and up events at random locations. You'll need to P/Invoke PostMessage() and use Control.GetChildAtPoint() to generate the window handle for the WM_LBUTTONDOWN/UP messages. Application.DoEvents() in your test loop to get the event handlers to run.

Hans Passant
That sounds like a good start. I found this MSDN article that seems to have a lot of good info outlining that approach: http://msdn.microsoft.com/en-us/magazine/cc163738.aspx
Ogre Psalm33
I think I'm going to go with this approach instead of one of the obscure fuzz-testing tools I found in my search. Rolling my own approach by simulating events like this should allow me to integrate it into my existing NUnit test framework.
Ogre Psalm33
A: 

Doing some searching around the net, I found 2 links with useful tools and information on Fuzz-testing WinForms apps:

  • Monkey Fuzz Testing - An alpha-status tool on codeplex that appears to be pretty close to what I want. From the site: "MonkeyFuzz primarily sends random keyboard and mouse events to a program, but it can record the actions along the way. This allows them to be replayed useful for regression testing)." I may try it out and report back my findings.
  • A Paper on Random Testing from the University of Wisconsin CS Department. This is dated 2000-2002, but does seem to contain some good info, and links to tools they used in their study. However, it appears the tools may be at least 10 years out-of-date.
Ogre Psalm33