问题描述
我有一个包含TestInitialize
和TestCleanup
的基类.然后,我还有从该类继承的其他测试类.当来自派生类的测试失败时,TestCleanup
应该执行某些操作.
I have a base class that has a TestInitialize
and a TestCleanup
in it. I then have other test classes which inherit from this class. The TestCleanup
is supposed to perform certain actions when a test from the derived class fails.
在实际测试中测试失败时,将执行TestCleanup
.但是,当TestInitialize
中的测试失败时,甚至不会执行TestCleanup
.为什么会发生这种情况,有没有办法让TestCleanup
被调用?
The TestCleanup
gets executed when the test fails in the actual test. However, when the test fails in the TestInitialize
, the TestCleanup
doesn't even get executed. Why does this happen and is there a way to get the TestCleanup
to get called anyway?
我不认为TestInitialize
和TestCleanup
都在基类中这一事实完全导致了此问题,我只是想提供更多信息,以防万一.
I don't think that the fact that the TestInitialize
and TestCleanup
are in a base class is at all causing this issue, I just wanted to give more information just in case it was.
推荐答案
这是一个已知问题.好像已经报告给Microsoft connect.
This is a known issue. It looks like it has been reported to Microsoft connect.
这篇关于当MSTest在TestInitialize中失败时,为什么不执行TestCleanup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!