.net 核心项目代码覆盖 Visual Studio 2017 [英] .net core projects code coverage visual studio 2017

查看:26
本文介绍了.net 核心项目代码覆盖 Visual Studio 2017的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio Enterprise 2017 开发我的 .net 核心项目.

I am using Visual Studio Enterprise 2017 to develop my .net core projects.

我的解决方案还有一些单元测试项目,我想查看我当前的代码覆盖率.

My solution also has some unit test projects and I want to view my current Code coverage.

当我点击测试 -> 分析代码覆盖率 -> 所有测试.我所有的单元测试都运行了,但在代码覆盖率结果中它只报告了我的单元测试项目的代码覆盖率,这对我来说没有任何意义.

When I clicked Test -> Analyze Code Coverage -> All tests. All my unit tests ran but in Code Coverage Results it only reported code coverage for my unit test projects which doesn't make any sense to me.

问题 1:你们和我有同样的问题吗?有什么解决办法吗?我还需要在 VSTS 中设置构建定义来报告代码覆盖率.

Question 1: Do you guys experience the same issue with me? Any solution for this? I also need to set up build definition in VSTS to report code coverage.

问题 2:当我右键单击以调试我的单元测试的 1 时.它执行我所有的单元测试.这是 VS2017 的 bug 吗?

Question 2: Also when I right clicked to debug 1 of my unit test. It executes ALL of my unit tests. Is this a bug in VS2017?

Update1:​​我找到了这个主题:https://github.com/Microsoft/vstest/issues/597

Update1: I found this topic: https://github.com/Microsoft/vstest/issues/597

推荐答案

即使是固定"版本我也有问题(只能看到测试项目的代码覆盖率,而不是我正在测试的实际项目).为了解决这个问题,我从测试项目中删除了 <DebugType>Full</DebugType>.

Even with the "fixed" version I had issues (Only able to see code coverage for the test projects, not the actual projects I was testing). To workaround the problem I removed the <DebugType>Full</DebugType> from the test project.

所以,总结一下:

  1. 将包 Microsoft.CodeCoverage (1.0.3) 添加到您的测试项目中.

  1. Add package Microsoft.CodeCoverage (1.0.3) into your test project.

在.csproj文件上添加<DebugType>Full</DebugType>标签on我们希望查看代码覆盖率值的项目(在 <PropertyGroup> 内,如 vstest github 链接).

Add the <DebugType>Full</DebugType> tag on the .csproj file on the projects we want to see code coverage values (inside <PropertyGroup> as explained on the vstest github link).

我的设置(最小设置?)

My setup (Minimal setup?)

  • xunit (2.3.1)
  • xunit.runner.visualstudio (2.3.1)
  • Microsoft.NET.Test.Sdk (15.3.0)
  • Microsoft.CodeCoverage (1.0.3)
  • Visual Studio 企业版 2017 (15.4.1)

这篇关于.net 核心项目代码覆盖 Visual Studio 2017的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆