是否可以在 MSTest / VS 单元测试中进行确定性 ClassCleanup?
即在测试类中的所有测试之后立即执行一次使用 ClassCleanup 属性装饰的方法? (就像 NUnit 中的 TestFixtureTearDown)。有什么解决方法吗?
在 TestInitialize 和 TestCleanup 中嵌入这种繁重的设置/拆卸的替代方案只会增加测试执行时间。
过去一周我对两者进行了比较。 (这是我发现的 NUnit 与 MSTest 。在 MSTest 中没有太多的飞行时间,所以如果我犯了一个错误,请随时以评论的形式发表更正。)
就我而言,这个特定的项目是一个精彩的项目 担心的。如果您想了解更多详细信息,请阅读博客文章的第一部分。
i.e. to have the method decorated with ClassCleanup attribute executed once immediately after all tests in a test class ? (like TestFixtureTearDown in NUnit). Any workarounds ?
The alternative of embedding this heavy setup/teardown in TestInitialize and TestCleanup would just drive up the test execution times.
I was comparing the two over the past week.
(Here's what I found NUnit vs MSTest . Don't have a lot of flying time in MSTest, so if I've made a mistake, please feel free to post corrections as comments..)
This particular item is a showstopper as far as I am concerned. Read the first section of the blog post in case you'd like more details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是真的,但是在所有测试完成运行后,类会被批量卸载。
例如
类初始化1
测试初始化1
测试方法11
测试清理1
测试初始化1
测试方法12
测试清理1
类初始化2
测试初始化2
测试方法21
测试清理2
测试初始化2
测试方法22
测试清理2
测试初始化2
测试方法23
测试清理2
类清理1
类Cleanup2
It's true, but classes are bulk-unloaded after all tests finished running.
E.g.
ClassInitialize1
TestInitialize1
TestMethod11
TestCleanup1
TestInitialize1
TestMethod12
TestCleanup1
ClassInitialize2
TestInitialize2
TestMethod21
TestCleanup2
TestInitialize2
TestMethod22
TestCleanup2
TestInitialize2
TestMethod23
TestCleanup2
ClassCleanup1
ClassCleanup2
根据 MSDN ClassCleanup 运行为如下:
当我读到它时,这意味着班级中的测试已经运行。
According to MSDN ClassCleanup is run as follows:
As I read it, that means when the tests in the class hae been run.