Testing Error Handling

What are some ways of testing that your application is dealing with error situations correctly? More questions: How do you simulate system errors? How do you simulate database failure? How do you test that errors are propagating correctly? -- AsimJalis


For databases, comm links, and the like, I use FakeTheSideEffects. For functions which can throw exceptions, I have the unit test intentionally cause the exception (by passing in the appropriate wrong thing or causing the fake external interface to report an error), and then make sure that the correct exception was thrown. Not ideal, but it works a whole heck of a lot better than nothing, and isn't too hard to do.


An after the fact approach is when you find a bug, fix the error reporting for the bug first, then fix the bug. Ideally, you should use the approach above, however.


If you find FakeTheSideEffects difficult MockObjects may be easier.


Just wanted to share the ultimate unit test for anything manipulating a windows file. I made a file named:

!.£$%^'@ &,()-+[].txt

This is a valid file name and all of your file I/O code should handle it. I keep that file around and throw it at everything! For extra points, make it 0 bytes.


CategoryTesting


EditText of this page (last edited February 21, 2006) or FindPage with title or text search