0

I have a sample unit/functional test example below.

What I want is that, launching Console before tests runs and outputting Console.WriteLine into this console.

enter image description here

public class User
        {
            public string UserName { get; set; }
        }
        [TestMethod]
        public void TestUserInitialize()
        {
            // Launch Console, and see Console.WriteLine output here?
            User user = new User();
            InitializeUser(user);
        }

        private void InitializeUser(User user)
        {
            Console.WriteLine("Checking user: " + user.UserName);
            Assert.IsTrue(!string.IsNullOrEmpty(user.UserName));
        }

Currently I can do Debug.WriteLine to see output in Visual Studio, but I would like to make it easier to track in separate console window. Also it will help to execute console examples given on internet, if they are already using Console.WriteLine.

Is there any easy way to do this?

Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158
  • I thought you have to create separate classes for unit tests. And then you can use static constructor of those to initialize your test environment, no? – Sinatr Jul 05 '18 at 14:04
  • I just throw dummy example here. I can do that in real life cases. My main problem is that, when I pick and run a unit test, output to be shown in a new console. – Teoman shipahi Jul 05 '18 at 14:05
  • You may know these bits already, but if you don't, might help :) https://stackoverflow.com/questions/11209639/can-i-write-into-console-in-a-unit-test-if-yes-why-the-console-window-is-not-o – Davesoft Jul 05 '18 at 15:42

0 Answers0