.NET 应用程序的故障注入?
我想知道是否有人知道自动将常见错误注入正在运行的 .NET 程序的工具或技术。诸如...
- 在分配时随机注入 OutOfMemoryException 在
- 尝试访问文件时随机注入 FileNotFoundException
- 在使用套接字时随机注入 IO 或网络异常。
因此,我确实在寻找一种方法来拦截 CLR 中的某些特定调用,类似于 AppVerifier 对本机 Win32 代码所做的操作。目的是在开发人员无法控制的大量错误情况下测试应用程序,并确保处理此类情况。
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 OutOfMemoryException upon allocation
- Randomly inject FileNotFoundException upon trying to access a files
- Randomly inject IO or Network exceptions upon using a socket.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有一个名为 TestAPI 的 Codeplex 项目可以进行运行时错误注入。您需要查看其托管代码错误注入API 。它使用 CLR 分析 API 在运行时拦截方法调用并修改其行为。
查看示例 查看如何在已编译的 exe 中的方法调用上注入异常。
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 似乎是您最好的选择。
如果您想抛出
FileNotFoundException
来模拟测试,您可以执行以下操作。在您的生产代码中,您有这样的方法
在您的测试代码中,您可以像这样伪造
OpenProject
调用当您的代码命中
OpenProject
时,会出现FileNotFoundException< /code> 将被抛出。
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
And in your test code, you can fake the
OpenProject
call like thisAnd when your code hit
OpenProject
, aFileNotFoundException
will be thrown.这与您的要求并不完全相符,但它是相关的,并且可能有助于实现改进应用程序中的异常处理的同一目标。
红门异常猎人
http://www.red-gate.com/products/Exception_Hunter/index.html htm
我没有使用过这个特定的产品,但我使用过的其他 redgate 产品都很棒。
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.
我不知道如何“随机”注入这些东西,但我建议您模拟通常不在您控制之下的部分,并让模拟在某些测试中抛出异常。
I don't know how one would "randomly" inject these things, but I would recommend you mock out the part that's not normally under your control, and have the mock throw an exception in some of your tests.