简体   繁体   English

Visual Studio 2010-MSTest和代码覆盖率分析异常行为

[英]Visual Studio 2010 - MSTest and code coverage analysis unusual behavior

I have a Visual Studio 2010 C# solution using MSTest for unit testing. 我有一个使用MSTest进行单元测试的Visual Studio 2010 C#解决方案。 Code coverage analysis is enabled and has been working without any issues until now. 代码覆盖率分析已启用,并且到目前为止一直没有任何问题。

Within the last few days, the code coverage analysis report has been returning strange results. 在过去的几天中,代码覆盖率分析报告一直在返回奇怪的结果。 For example, I have classes A, B, C and D. Classes A, B and C all have unit tests, but D does not. 例如,我有A,B,C和D类。A,B和C类都有单元测试,而D没有。 When unit testing is run, all unit tests are shown to have run and passed. 运行单元测试时,显示所有单元测试都已运行并通过。 I can look at individual tests and see they run. 我可以查看各个测试,看看它们是否运行。 However, the code coverage report will not show class A at all, class B will have 50% coverage when it is actually 100% covered, class C will be correct and somehow class D will have 25% coverage, even though there are no unit tests for it. 但是,代码覆盖率报告完全不会显示A类,而实际上没有100%覆盖时,B类将覆盖50%,C类将是正确的,D类将以某种方式覆盖25%,即使没有单位测试。 Percentages are for example purposes. 百分比仅供参考。

I've cleaned and rebuilt, deleted the bin and obj folders entirely, downloaded the code from Subversion into a fresh folder, etc., etc. Google is not giving me help on this. 我已经清理并重建,完全删除了bin和obj文件夹,将代码从Subversion下载到了新文件夹中,等等,等等。Google在这方面没有给予我帮助。

I realise this is an old question, but it may help inexperienced developers. 我意识到这是一个老问题,但它可能对经验不足的开发人员有所帮助。

It is possible that class A calls code in class D, which is run as part of the tests for class A. This then creates a bit of coverage in class D. 类A可能调用类D中的代码,该代码作为类A的测试的一部分运行。然后,这会在类D中创建一些覆盖范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM