如何从MSTest获取测试结果状态? [英] How to get test result status from MSTest?

查看:340
本文介绍了如何从MSTest获取测试结果状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在NUnit中,我可以从context.Result.State获得测试结果.如果它是NUnit.Framework.TestState.Success,那么我知道测试通过了.

In NUnit, I can get the test result from context.Result.State. If its NUnit.Framework.TestState.Success, then I know the test passed.

在MSTest中,如何获取该信息?

In MSTest, how do I get that info?

我看到了context.Properties.Keys,但是他们都没有提到测试结果的状态.

I saw context.Properties.Keys, but none of them speak of the status of the test result.

推荐答案

使用

Use the TestContext.CurrentTestOutcome property in the TestCleanup method:

[TestClass]
public class UnitTest
{
    private TestContext TestContext { get; set; }

    [TestCleanup]
    public void TestCleanup()
    {
        if (TestContext.CurrentTestOutcome == UnitTestOutcome.Passed)
            //do something
    } 

    [TestMethod]
    public void TestMethod()
    {
    }
}

这篇关于如何从MSTest获取测试结果状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆