NUnit-是否可以在TearDown中检查测试是否成功? [英] NUnit - Is it possible to check in the TearDown whether the test succeeded?
本文介绍了NUnit-是否可以在TearDown中检查测试是否成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让我的TearDown方法在应用某些逻辑之前检查之前的测试是否成功。有没有简便的方法?
I would like to have my TearDown method check whether the previous test was a success before it applies some logic. Is there an easy way to do this?
推荐答案
如果要使用TearDown来检测NUnit 3.5的上次测试状态,它应该是:
If you want to use TearDown to detect status of last test with NUnit 3.5 it should be:
[TearDown]
public void TearDown()
{
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
{
//your code
}
}
这篇关于NUnit-是否可以在TearDown中检查测试是否成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文