[英]How can I see the results of my Unit Tests in VS2017?
I'm running unit tests on my GetModelAsync()
and CreateModelAsync()
methods in VS17. 我正在
GetModelAsync()
和CreateModelAsync()
方法上运行单元测试。 I then run Assert.Equal
checks on the model fields to ensure they match the expected values. 然后,我在模型字段上运行
Assert.Equal
检查,以确保它们与期望值匹配。
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? 有没有办法做到这一点?
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.
在执行此操作之前,您可能需要先将复杂对象序列化为JSON。 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. 注意,对于Visual Studio的内置测试运行器,您必须执行一些步骤才能看到控制台输出。 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. 在“测试资源管理器”窗口中,单击测试的名称,然后在结果面板中单击“
Output
链接,这将打开一个单独的窗口以显示控制台输出。 It's all very unintuitive. 这都是非常不直观的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.