How to write a NUnit test for an NUnit add-in?

情到浓时终转凉″ 提交于 2019-12-11 12:29:34

问题


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

回答1:


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




回答2:


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...



来源:https://stackoverflow.com/questions/3927349/how-to-write-a-nunit-test-for-an-nunit-add-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!