0

I have the following unit test:

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

namespace MyModule.MyName.Tests
{
    [TestClass()]
    public class ClassName
    {

        [TestMethod()]
        public void MethodName()
        {
            string dictString = //some value

            System.Diagnostics.Debug.WriteLine("dictString is:");
            System.Diagnostics.Debug.WriteLine(dictString);

            Console.WriteLine("dictString is:");
            Console.WriteLine(dictString);

           //some assert

        }
    }
}

I am just trying to print the value of the variable dictString from the test. However, nothing is printed.

When I select the test and run it, I get this in the Output window:

[Informational] ========== Discover test finished: 1 found (0:00:01.6269603) ==========
[Informational] ------ Run test started ------
[Informational] ========== Run test finished: 1 run (0:00:00.8045498) ==========

None of my logging is printed. So, how can I print the values of the variables from the test?

bsky
  • 19,326
  • 49
  • 155
  • 270
  • That's not how you get information out of a unit test. Typically you'll setup some conditions, perform an action and assert on the results. The information comes from the result of the asserts. What are you trying to do here? – Alejandro Dec 14 '17 at 15:27
  • I'm just trying to find out the value of a variable, in this case `dictString`. I'm new to Visual Studio and I don't know how to do this otherwise. – bsky Dec 14 '17 at 15:28
  • 1
    But for what purpose? Why not put an assert on its value? If the test fails, the error message will clearly point at the offending value. If you further customize the failure message, you get an additional information. – Alejandro Dec 14 '17 at 15:29
  • I just see that the test is failing but I can't see why. – bsky Dec 14 '17 at 15:33
  • Add the asserts you're using and what is failing. The stacktrace gives a strong indication of this. – Alejandro Dec 14 '17 at 16:29

0 Answers0