Reputation: 2397
I'm running unit tests on my GetModelAsync()
and CreateModelAsync()
methods in VS17. I then run Assert.Equal
checks on the model fields to ensure they match the expected values.
I want to be able to see the final state of my models, which will help me determine why a test is failing or allow me to manually check my models. I'm thinking something similar to tracking variables in the debugger would make sense, although I don't want to actually run the debugger.
Is there a way to do this?
Upvotes: 1
Views: 3720
Reputation: 8665
You can write to the console in your tests and it will show up in Test Explorer. You may want to serialize complex objects to JSON first before doing this. For example:
Console.WriteLine(JsonConvert.SerializeObject(myObject));
Note, for Visual Studio's built in test runner, you have to go through a few steps to see the console output. In the Test Explorer window, click the name of your test, then in the results panel click the Output
link, which will open a separate window to show the console output. It's all very unintuitive.
Upvotes: 3