使用 Visual Studio 测试套件/NUnit 自动化集成测试 MSMQ 的最佳方法是什么?
我想为我正在编写的 MSMQ 应用程序创建一系列自动化单元测试。 在我看来,挑战在于如何适应测试方法中的事件处理程序。 也就是说,我从测试方法发送一条消息,并且需要将结果返回到该消息已被接收并处理的测试方法。 我不知道如何实现这一点,任何方向将不胜感激。
I would like to create a series of automated unit tests for an MSMQ application I am writing. As I see it, the challenge is how to accommodate the event handlers from the test method. That is, I send a message from the test method and need to return a result back to that test method that the message has been received and handled. I have no clue as to how to accomplish this and any direction would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否正在寻找一种编写单元测试的方法,其中被测系统认为它正在从队列接收事件,但您不想在测试期间使用真正的队列?
查看Rhino Mocks。 它允许您创建队列接口的模拟版本,然后在测试期间从中引发事件。 测试 Requester.DoSomething() 方法的一些伪代码可能如下所示:
查看 Rhino 模拟 wiki 了解所有细节。
Are you looking for a way to write unit tests where the system under test thinks it's receiving events from a queue, but you don't want to use a real queue during the tests?
Check out Rhino Mocks. It lets you create a mock version of your queue interface, and then raise events from it during the test. Some pseudo code to test the Requester.DoSomething() method might look like this:
Check out the Rhino mocks wiki for all the details.
通常,单元测试应该隔离正在测试的方法。 我不熟悉 MSMQ,但您通常会创建一个模拟对象并将其传递给您的生产方法。 然后,您可以感知该方法对模拟对象执行的操作,以验证其行为是否正确并发送预期的响应。 制作方法不会知道有什么区别。 单元测试更多的是确保您的方法在孤立的情况下按预期运行。
听起来就像您正在寻找的是集成测试。 您仍然可以使用单元测试框架来完成此任务,但我不会将它们包含在自动构建中。 我会将它们转移到专用的测试机器上。 单元测试通常会停止构建,因为它们表明类或方法的行为不符合预期。 正如集成测试所示,方法或类没有按预期相互交互。
Typically a unit test should isolate the method being tested. I'm not familiar with MSMQ but you would normally create a mock object and pass that to your production method. Then you can sense what the method did to the mock object to verify its behaving correctly and send the expected response. The production method won't know the difference. Unit testing is more to ensure your methods are behaving as expected in isolation.
Sound's like what your looking for is an integration test. You can still use unit testing frameworks to accomplish this but I wouldn't include them in an automated build. I would move them to a dedicated test machine(s). Unit tests typically halt a build as they indicate a class or method that isn't behaving as expected. Where as integration tests indicate and methods or classes aren't interacting with each other as expected.