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.
Try using TestContext.WriteLine()
which outputs text in test results.
Example:
[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...");
}
}
The "magic" is described in MSDN:
To use TestContext, create a member and property within your test class [...] The test framework automatically sets the property, which you can then use in unit tests.