Multiple folks have asked in forums on how to log a message from a Coded UI Test for tracing\debugging purpose. I know of as many as 5 ways of doing this from any test type (Coded UI Test, Unit Test etc). Try this code out -
1: [TestMethod]
2: public void CodedUITestMethod1()
3: {
4: Console.WriteLine("Console.WriteLine()");
5: Console.Error.WriteLine("Console.Error.WriteLine()");
6: TestContext.WriteLine("TestContext.WriteLine()");
7: Trace.WriteLine("Trace.WriteLine()");
8: Debug.WriteLine("Debug.WriteLine()");
9: }
If you check the test result window, you should see output like -
So clearly all 5 ways are working i.e. corresponding messages are getting logged. Each of these ways have their own advantages and disadvantages -
In short, use TestContext.WriteLine wherever possible.