如何从写单元测试的输出? [英] How to write output from a unit test?

查看:691
本文介绍了如何从写单元测试的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的单元测试中的任何调用要么 Debug.Write(线) Console.Write(线)简单地被跳过,同时调试和从不打印输出。调用从类中我使用的是做工精细这些功能。

Any call in my unit tests to either Debug.Write(line) or Console.Write(Line) simply gets skipped over while debugging and the output is never printed. Calls to these functions from within classes I'm using work fine.

据我所知,单元测试是为了实现自动化,但我还是希望能够从单元测试输出消息。

I understand that unit testing is meant to be automated, but I still would like to be able to output messages from a unit test.

推荐答案

尝试使用TestContext.WriteLine()它的测试结果输出文本

Try using TestContext.WriteLine() it outputs text in test results.

例如:

    [TestClass]
    public class UnitTest1
    {
        private TestContext testContextInstance;
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void TestMethod1()
        {
            TestContext.WriteLine("Message...");
        }
    }



魔术师中的MSDN 为测试框架自动设置属性,然后可以使用在单元测试中。

The "magic" is described in MSDN as "The test framework automatically sets the property, which you can then use in unit tests."

这篇关于如何从写单元测试的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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