我试图找到我的 .Net 代码用来提醒 Visual Studios 测试失败、通过或被忽略的值。我希望能够使用它来确定我们数据库中的基本跟踪测试是否通过或失败。
但是,如果没有在每个测试的末尾放置一个变量并将其设置为“通过”,我不知道在运行拆卸代码时如何区分失败或通过的测试。
感谢您的帮助!
最佳答案
您可以使用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 .
关于c# - 如何确定测试是否通过或失败以用于 TearDown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23793907/