如何为 NUnit 插件编写 NUnit 测试?
我正在研究这个堆栈溢出答案的变体,它提供了可靠的测试清理。如何为 NUnit 插件编写单元测试?
检查 NUnit 如何进行自测试,我确定:
- 您可以编写通过的测试,验证 NUnit 对于失败测试的正确行为。
- 您可以在单独的程序集中针对测试装置编写单元测试(否则被测装置将与单元测试一起执行)
- 使用 NUnit.TestUtilities.TestBuilder 创建装置并调用 TestSuite.Run 方法。
我没有看到加载项过程的任何测试。我在安装和执行之间的某个时候发生了错误。我将如何单元测试实现以下内容?
- IAddin.
- 安装ITestDecorator.Decorate
I'm working on a variation of this stack overflow answer that provides reliable cleanup of tests. How do you write unit tests for NUnit addins?
Examining how NUnit self tests, I have determined:
- You can write tests, that pass, that verify correct behavior of NUnit for failing tests.
- You write unit tests against test fixtures in a separate assembly (otherwise the fixtures under test will execute with your unit tests)
- Use NUnit.TestUtilities.TestBuilder to create fixtures and call TestSuite.Run method.
What I don't see are any tests of the add-in process. I've got errors occurring sometime between install and execution. How would I unit test implementations the following?
- IAddin.Install
- ITestDecorator.Decorate
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是某人写的一篇文章,他找到了一种方法来做到这一点:操纵 NUnit 插件实现中的一些单例来交换他的插件。
http://www.bryancook.net/2009 /09/testing-nunit-addins-from-within-nunit.html
Here's an article by someone who hacked a way to do it: manipulating some of the singletons in the NUnit add-in implementation to swap his add-in in and out.
http://www.bryancook.net/2009/09/testing-nunit-addins-from-within-nunit.html
有时,最简单的事情就是运行集成测试。自从我使用 NUnit 插件 API 以来已经有一段时间了,所以我不能真正谈论任何现有的可扩展性机制的单元测试。如果您查看了 NUnit 源代码但没有找到任何内容,那么我猜这不是使用 TDD 测试甚至编写的东西。
就像我说的,有时运行集成测试更容易。例如,让您的插件将某些内容打印到输出流,并让您的测试验证是否写入了确切的消息。这样您就可以测试插件的安装和初始化是否成功。
希望有帮助...
Sometimes, the easiest thing to do is run integration tests. It been a while since I played with the NUnit add-in API, so I can't really say regarding any existing unit tests for the extensibility mechanism. If you have looked through NUnit source code and haven't found any, then I guess that is not something that was tested or even written using TDD.
Like I said, sometimes it's easier to just run integration tests. Have your addon, for example, print something to the output stream, and have your test verify that the exact message was written. This way you could test that both the installation and initialization of your plugin succeeded.
Hope that helps...