我试图找到我的.Net代码用来警告Visual Studios测试失败,传递或被忽略的值。我希望能够使用它来确定测试是否已通过或未通过我们数据库中的基本跟踪。
但是,如果没有在每个测试结束时放置变量并将其设置为&#34;传递&#34;,我不知道如何在运行我的拆卸代码时区分失败或通过的测试。< / p>
感谢您的帮助!
答案 0 :(得分:2)
您可以使用TestContext
:
// Use the necessary namespace
using NUnit.Framework;
...
[TearDown]
public void TearDown()
{
if (TestContext.CurrentContext.Result.Status == TestStatus.Failed)
{
// Your test failed, handle it
}
}
请参阅文档here。