I am wondering if anyone knows of tools or techniques to automatically inject common faults into a running .NET program. Stuff like...
So I'm really looking for a way to intercept some specific calls in the CLR similar to what AppVerifier does for native Win32 code. The purpose is to test apps under lots of error conditions beyond the developers control and to make sure such conditions are handled.
There is a codeplex project called TestAPI that can do runtime fault injection. You need to look at its managed code fault injection API. It uses the CLR profiling API to intercept method calls at runtime and modify their behaviour.
Have a look at an example to see how to inject an exception on a method call in an already compiled exe.
Typemock Isolator seems to be your best bet.
Here's what you can do, if you want to throw a FileNotFoundException
to simulate testing.
In your production code, you have such method
public static Project OpenProject(string filePath)
And in your test code, you can fake the OpenProject
call like this
Isolate.WhenCalled(()=>Project.OpenProject(nulll)).WillThrow(new FileNotFoundException());
And when your code hit OpenProject
, a FileNotFoundException
will be thrown.
This isn't exactly on point with what your asking, but it's related and may be helpful toward the same goal of improving exception handling in your app.
redgate Exception Hunter http://www.red-gate.com/products/Exception_Hunter/index.htm
I haven't used this particular product but other redgate products I've used were great.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With