Unit tests are failing when run from dotCover

点点圈 提交于 2019-12-11 05:52:50

问题


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.

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

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.

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

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

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

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


回答1:


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.

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.

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

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

This has resolved my problem.




回答2:


Make sure your build service account have enough permission to run the dotcove.exe. According to your E:\JetBrains\Installations\dotCover05\dotCover.exe Seems you didn't install for all users on the build agent. Which should installed under %ProgramFiles(x86)% not %LOCALAPPDATA%\JetBrains\Installations.

Try to use CoreInstructionSet parameter in your dotCover as a workaround for your situation. Details see below picture.

After doing this try to run the build again.




回答3:


You can also try this method if it is failed by the file copying: Shadow-copying in dotCover: if your NUnit tests fail during continuous testing .



来源:https://stackoverflow.com/questions/40082990/unit-tests-are-failing-when-run-from-dotcover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!