问题描述
NUnit 是否支持类似于 Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute 可以应用于静态方法吗?
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?
这将在程序集中的所有测试完成后运行.我目前使用的是 NUnit 2.6.0.
This would be run after all the tests within the assembly have completed. I am currently using NUnit 2.6.0.
推荐答案
事实证明这个功能确实存在于 NUnit 中,只是不是很明显或直观.
It turns out this functionality does exist in NUnit it is just not very obvious or intuitive.
根据我在此处提出的功能请求中的 Charlie Poole,他说以下内容可行,这是他的直接引述.
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.
使用 [SetUpFixture] 装饰任何命名空间之外的类.使用 [TearDown] 装饰该类的方法.如果你喜欢,装饰一下另一个使用 [SetUp].
与您要求的不同:
这个名字在这个用法中有点不明显.
The name makes it a little unobvious in this usage.
NUnit 允许使用任意数量的这些并将它们全部调用,但不保证顺序.这是设计使然.
NUnit allows any number of these and calls them all, without any guarantee of ordering. This is by design.
它可以应用于静态或实例方法.如果它是一个实例方法,该类必须有一个默认构造函数,它会以整个测试运行的生命周期创建.这也是由设计.
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.
现在这不是很漂亮,但它应该实现相同的功能,也许他会在 3.0 中使它更简洁一些.:)
Now this is not pretty but it should achieve the same functionality, and maybe he will make it a little cleaner in 3.0. :)
这篇关于NUnit 是否支持 Assembly Teardown 的概念?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!