如何将整个班级标记为“不确定”?
我有一个名为 MyClass 的测试类。 MyClass 有一个 TestFixtureSetUp 来加载一些初始数据。当加载初始数据失败时,我想将整个类标记为不确定。就像有人通过调用 Assert.Inconclusive() 将测试方法标记为 Inconclusive 一样。
有什么解决办法吗?
I've a test class named MyClass. MyClass has a TestFixtureSetUp that loads some initial data. I want to mark whole class as Inconclusive when loading initial data fails. Just like when somebody marks a test method Inconclusive by calling Assert.Inconclusive().
Is there any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
Setup
解决这个问题,方法是在数据加载失败时向其发出信号。例如:
Nunit 不支持
TestFixtureSetUp
中的Assert.Inconclusive()
。如果调用了 Assert.Inconclusive() ,则夹具中的所有测试都会显示为失败。You can work around it using
Setup
by signaling it when a data loading failed.For example:
Nunit does not support
Assert.Inconclusive()
in theTestFixtureSetUp
. If a call toAssert.Inconclusive()
is done there all the tests in the fixture appear as failed.试试这个:
在您的
TestFixtureSetUp
中,在类中存储一个静态值,以指示数据是否尚未加载、已成功加载或已尝试加载但未成功加载。在每个测试的
SetUp
中,检查该值。如果指示加载不成功,立即调用
Assert.Inconclusive()
轰炸。Try this:
In your
TestFixtureSetUp
, store a static value in the class to indicate whether the data has yet to be loaded, was successfully loaded, or was attempted but unsuccessfully loaded.In your
SetUp
for each test, check the value.If it indicates an unsuccessful load, immediately bomb out by calling
Assert.Inconclusive()
.