Does NUnit support the concept of an Assembly Teardown?

久未见 提交于 2019-12-21 10:52:04

问题


Does NUnit support the concept of an Assembly Teardown similar to the Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute that can be applied to a static method?

This would be run after all the tests within the assembly have completed. I am currently using NUnit 2.6.0.


回答1:


It turns out this functionality does exist in NUnit it is just not very obvious or intuitive.

According to Charlie Poole in the feature request I made for this functionality here, he states the following will work, which is a direct quote from him.

Decorate a class outside of any namespace with [SetUpFixture]. Decorate a method of that class with [TearDown]. If you like, decorate another with [SetUp].

Differences from what you are asking for:

  1. The name makes it a little unobvious in this usage.

  2. NUnit allows any number of these and calls them all, without any guarantee of ordering. This is by design.

  3. It can be applied to a static or instance method. If it's an instance method, the class must have a default constructor and it will be created with a lifespan of the entire test run. This is also by design.

Now this is not pretty but it should achieve the same functionality, and maybe he will make it a little cleaner in 3.0. :)




回答2:


There is no such concept in NUnit. But you can apply TestFixtureTearDownAttribute to method to free resources obtained by TestFixture.



来源:https://stackoverflow.com/questions/14288454/does-nunit-support-the-concept-of-an-assembly-teardown

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