Fault injection for .NET apps?

前端 未结 4 882
青春惊慌失措
青春惊慌失措 2020-12-31 06:20

I am wondering if anyone knows of tools or techniques to automatically inject common faults into a running .NET program. Stuff like...

  • Randomly inject an OutO
4条回答
  •  清酒与你
    2020-12-31 06:41

    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.

提交回复
热议问题