我试图从[TestMethod]方法中显示一些信息。
通常我们使用NUnit并且Console.WriteLine
的行运行正常,我们可以在“输出”窗口中看到它,但是在这个项目中我们必须使用嵌入VS2010和Console.WriteLine
的测试工具来做因为我们看不到任何东西而跑步。
我想要的是以这种方式或多或少地在'输出'窗口上显示跟踪消息:
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.
}
}
}
}
答案 0 :(得分:27)
您应该将Console.WriteLine
替换为System.Diagnostics.Debug.WriteLine(...)
,您将在Visual Studio调试输出窗口中看到输出。
编辑:刚刚发现这是一个重复的问题,请看这里:
How to write to Console.Out during execution of an MSTest test
答案 1 :(得分:18)
您可以使用testContextInstance.WriteLine(string s);
答案 2 :(得分:5)
您可以通过使用选项Console.WriteLine()
运行MSTest
命令行来强制显示/detail:stdout
。
例如:
MSTEST /testcontainer:MyDllToTest.dll /testSettings.local.TestSettings /detail:stdout
(注意我使用/testSettings
来阻止testResults目录中的DLL复制(部署)