从dotCover运行时,单元测试失败 [英] Unit tests are failing when run from dotCover

查看:164
本文介绍了从dotCover运行时,单元测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TFS 2015构建,该构建可构建我们的一个应用程序(这是一个ASP.NET Web API应用程序).作为构建过程的一部分,它将运行我们的单元测试.

I have a TFS 2015 build which builds one of our applications (it's an ASP.NET Web API application). As part of the build process it runs our unit tests.

我有一个 Visual Studio Tes t构建步骤,该步骤可以运行这些单元测试,并且都可以通过.

I have a Visual Studio Test build step which runs these unit tests and they all pass okay.

然后我从同一版本中运行 dotCover 以确定代码覆盖率(不,因为我们没有企业许可证,所以我们不使用内置代码覆盖率).但是,从 dotCover 运行时,所有相同的单元测试都将失败.

I then run dotCover from this same build to determine code coverage (no we don't use the built-in code coverage as we don't have enterprise licences). However, when run from dotCover all the same unit tests fail.

我使用脚本步骤来运行批处理文件,该文件将按如下所示调用 dotCover .

I use a script step to run a batch file which invokes dotCover as follows.

E:\ JetBrains \ Installations \ dotCover05 \ dotCover.exe分析coverage.xml/LogFile=dotcover.log

dotCover 日志文件似乎并未提供任何有关单元测试失败的指示.

The dotCover log file doesn't seem to give any indications as to why the unit tests have failed.

有什么想法为什么单元测试从 Visual Studio Test 构建步骤运行时通过,而从 dotCover 运行时失败?

Any ideas why the unit tests pass when run from the Visual Studio Test build step and then fail when run from dotCover?

推荐答案

问题似乎与以下事实有关:我的构建使用XML文件来保存某些数据值.在TFS下运行时,VSTest可以找到此XML文件,而dotCover不能找到.

It seems that the problem is related to the fact that my build uses an XML file to hold certain data values. This XML file is found by VSTest when run under TFS but not by dotCover.

当dotCover运行时,它会创建一个 TestResults 文件夹,然后将所有必需的文件复制到运行单元测试所需的文件中.复制所有文件(XML文件除外).我已将文件设置为"始终复制",因此无法理解为什么不复制此文件.我尝试将文件手动复制为批处理文件,但是文件夹结构是由dotCover创建的,因此直到我实际运行代码覆盖率之后,该文件夹结构才存在.

When dotCover runs it creates a TestResults folder which it then copies all the necessary files to required to run the unit tests. All files are copied except the XML file. I have set the file to "Copy always" so can't understand why this file isn't copied. I tried copying the file manually as a batch file but the folder structure is created by dotCover so it doesn't exist until I actually run the code coverage.

解决方案是使用 DeploymentItem()属性装饰我的测试类.

The solution is to decorate my test classes with the DeploymentItem() attribute.

[TestClass]
[DeploymentItem("File.xml")]

这解决了我的问题.

这篇关于从dotCover运行时,单元测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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