开发者

How to Console.WriteLine from [TestMethod]? [duplicate]

开发者 https://www.devze.com 2023-04-05 11:51 出处:网络
This question already has answers here: How to write to Console.Out during execution of an MSTest test
This question already has answers here: How to write to Console.Out during execution of an MSTest test (6 answers) Closed 9 years ago.

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 VS2开发者_如何学编程010 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


You can use the testContextInstance.WriteLine(string s);


You can force the display of Console.WriteLine() by running MSTest command line with option /detail:stdout.

for example:

MSTEST /testcontainer:MyDllToTest.dll /testSettings.local.TestSettings /detail:stdout

(note I use /testSettings to prevent DLL copy (deployment) in a testResults directory

0

精彩评论

暂无评论...
验证码 换一张
取 消