如何从[TestMethod的] Console.WriteLine? [英] How to Console.WriteLine from [TestMethod]?

查看:1073
本文介绍了如何从[TestMethod的] Console.WriteLine?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示来自[TestMethod的]方法的一些信息。



通常我们使用NUnit的,并用线 Console.WriteLine 运行良好,我们可以看到它在输出窗口,但在这个项目上,我们一定要使用与VS2010 embebed测试工具和 Console.WriteLine 没有按':T运行,因为我们看不到任何东西。



我要的是在节目中跟踪消息以这种方式或多或少输出窗口:

 使用系统; 
使用System.Text;
使用System.Collections.Generic;
使用System.Linq的;
使用Microsoft.VisualStudio.TestTools.UnitTesting;


命名空间的Test1
{
[TestClass中]
公共类TestNum1
{
[TestMethod的]
公无效构造函数()
{
为(INT b = 1; b< 99; b ++){
Console.WriteLine(b.ToString()); //<<<<<<<这不显示输出。
Assert.AreEqual(B,B); //这只是一个愚蠢的样本。
}
}
}
}


解决方案

您应该替换 Console.WriteLine System.Diagnostics.Debug.WriteLine(...)



,你会看到在Visual Studio调试输出窗口中显示输出。



编辑:刚刚发现,现在这是一个重复的问题,请看这里:



如何在MSTest的测试的执行

$ b期间写信给Console.Out $ b

I am trying to show some information from a [TestMethod] method.

Usually we use NUnit and a line with Console.WriteLine runs fine and we can see it in 'output' window, but on this project we must to use Testing tools embebed with VS2010 and Console.WriteLine doesn't run because we cannot see anything.

What I want is show trace messages on the 'Output' Window in this way more or less:

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;


namespace Test1
{
    [TestClass]
    public class TestNum1
    {
        [TestMethod]
        public void Constructors()
        {
            for (int b = 1; b < 99; b++) {
                Console.WriteLine(b.ToString());  // <<<<<<< This don't show on Output.
                Assert.AreEqual(b, b);  // This is only a silly sample.
            }
        }
    }
}

解决方案

you should replace Console.WriteLine with System.Diagnostics.Debug.WriteLine(...)

and you will see the output in the Visual Studio Debug Output Window.

Edit: just found out now this is a duplicated question, look here:

How to write to Console.Out during execution of an MSTest test

这篇关于如何从[TestMethod的] Console.WriteLine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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