如何为 NUnit 插件编写 NUnit 测试?

发布于 2024-09-27 11:58:54 字数 402 浏览 2 评论 0原文

我正在研究这个堆栈溢出答案的变体,它提供了可靠的测试清理。如何为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹎☆浅夏丿初晴 2024-10-04 11:58:54

这是某人写的一篇文章,他找到了一种方法来做到这一点:操纵 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

┾廆蒐ゝ 2024-10-04 11:58:54

有时,最简单的事情就是运行集成测试。自从我使用 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文