简体   繁体   English

如何查看VS2017中的单元测试结果?

[英]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.

相关问题 我是否必须将经过测试的源文件添加到 VS2017 中的单元测试项目中? - Do I have to add tested source files to unit tests' project in VS2017? 如何将VS2017与Unity 2018一起使用 - How can I use VS2017 with Unity 2018 VS2017中的单元测试 - Unit testing in VS2017 VS2017项目的单元测试 - Unit Testing for VS2017 project 由于Windows操作系统不同,VS2017(vstest.console.exe)运行单元测试失败 - Running Unit Tests fails with VS2017 (vstest.console.exe) because the Windows OS is different 在VS2017中,是否有一种方法可以一次将所有失败的单元测试的名称复制到剪贴板? - In VS2017, is there a way to copy the names of all the failed unit tests to the clipboard at one time? 为什么我不能使用 vs 2015、vs2017、vs2019 在我的 windows 上创建 VC++ 空项目 - why I can not create a VC++ empty project on my windows using vs 2015 ,vs2017,vs2019 我可以将这个旧的csproj迁移到VS2017 csproj吗? - Can I migrate this old csproj to VS2017 csproj? 如何在编辑器中隐藏或减少VS2017的垂直线 - How can I hide or diminish VS2017's vertical lines in the editor VS2017:如何在不破坏我设置的过滤器的情况下在.vcxproj中编写每个文件选项? - VS2017: How can I write per-file options in .vcxproj, without breaking the filters I've set up?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM