如果启用了代码覆盖率,则TFS 2017测试任务在VS 2017构建计算机上运行失败 [英] TFS 2017 test task run fails on VS 2017 build machine if code coverage is enabled

查看:116
本文介绍了如果启用了代码覆盖率,则TFS 2017测试任务在VS 2017构建计算机上运行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用VS 2017 Enterprise在构建计算机上执行许多测试,我们在Visual Studio测试任务上启用了代码覆盖率.这将失败,并在TFS 2017控制台中出现以下错误:

We're executing a number of tests on a build machine with VS 2017 Enterprise where we've enabled code coverage on the Visual Studio test task. This fails with the following error in the TFS 2017 console:

##[section]Starting: Test Assemblies **\*test*.dll
Preparing task execution handler.
Executing the powershell script: d:\builds\4\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\1.0.60\VSTest.ps1
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform
Working folder: d:\builds\4\3\s
Executing C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe "d:\builds\4\3\s\Source\u.a.testassembly.dll"  /Settings:"C:\Users\username\AppData\Local\Temp\tmp9CCF.tmp" /EnableCodeCoverage /logger:trx /TestAdapterPath:"d:\builds\4\3\s"
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

##[error]The test source file "/EnableCodeCoverage" provided was not found.

对于Visual Studio 2015企业版,测试以代码覆盖率执行,没有错误.

With Visual Studio 2015 enterprise the tests were executed with code coverage with no error.

我们正在提供vstest.console.exe文件的路径作为自定义路径.

We're supplying the path for the vstest.console.exe file as a custom path.

如果我在TFS 2017"Visual Studio测试"任务的复选框中禁用了代码覆盖率,并使用了未指定代码覆盖率收集器的runsettings文件,则会执行测试,但不会报告任何代码覆盖率.

If I disable code coverage in the checkbox for the TFS 2017 'Visual Studio Test' task and use a runsettings file with no code coverage collectors specified, the tests are executed, but no code coverage is reported.

我还尝试了禁用代码覆盖率复选框和

I've also tried with the code coverage checkbox disabled and the

/EnableCodeCoverage

作为测试任务的命令行参数提供的参数.这提供了与上述相同的错误.

argument supplied as a commandline parameter on the test tasks. That provides the same error as above.

我发现很多人在VS 2017中存在代码覆盖问题,但似乎与.NET核心项目有关?

I've found a number of people having issues with code coverage in VS 2017 but that mostly seems related to .NET core project?

谢谢您的帮助! :-)

Thank you for your help! :-)

如果我尝试通过开发人员命令提示符运行vstest.console.exe,则无法成功指定/EnableCodeCoverage选项.它提供以下错误消息:

If I try to run vstest.console.exe through the developer command prompt I'm unable to successfully specify the /EnableCodeCoverage option. It provides the following error message:

Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The test source file "/EnableCodeCoverage" provided was not found.

如果在没有上述开关的情况下运行完全相同的命令,则不会出现此错误消息.

This errormessage does not appear if I run the exact same command without the above switch.

如果我改用Runsettings文件(在其中指定数据收集器),则会收到与JSON相关的错误:

If I use a Runsettings file instead, in which I specify the datacollectors, I get a JSON related error:

Cannot deserialize the current JSON object (e.g. {"name":"value"}) 
into type 'System.Collections.ObjectModel.Collection`1 Microsoft.VisualStudio.TestPlatform.ObjectModel.AttachmentSet]' 
because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.

如果使用/Diag开关,则会在日志文件中获得以下堆栈跟踪:

If I use the /Diag switch I get the following stacktrace in a logfile:

Stack Trace:
ved Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
ved Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
ved Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
ved Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
ved Newtonsoft.Json.Linq.JToken.ToObject[T](JsonSerializer jsonSerializer)
ved Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.JsonDataSerializer.DeserializePayload[T](Message message)
ved Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.<>c__DisplayClass6_0.<AfterTestRunEnd>b__0()
ved Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler runEventsHandler)

更新3

我们的构建服务器是Windows 2012标准服务器.除了安装Windows SDK有效负载外,我们能够安装VS 2017而没有任何错误.之后,我们必须手动安装Windows 8的Windows SDK,因为VS 2017 Enterprise中包含的Windows SDK有效负载未安装在Windows Server 2012上.

Update 3

Our build server is a Windows 2012 standard server. We were able to install VS 2017 without any errors except for the installation of the Windows SDK payload. We had to manually install Windows SDK for Windows 8 afterwards as Windows SDK payload included in the VS 2017 Enterprise didn't install on Windows server 2012.

我刚刚注意到Windows Server 2012不在

I've just noticed that Windows Server 2012 isn't on the list of supported operating systems for VS 2017?...

来自的详细输出 vstest.console.exe/? 从VS 2017开发人员命令提示符运行时,是:

The detailed output from vstest.console.exe /? when run from the VS 2017 developer command prompt is:

Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Usage: vstest.console.exe [Arguments] [Options] [[--] <args>...]]
Description: Runs tests from the specified files.

然后列出所有参数.

/Enablecodecoverage

找不到

开关.使用开始"菜单中的快捷方式打开开发人员命令提示符".

switch is nowhere to be found. The Developer Command Prompt is opened using the shortcut in the Start menu.

我尝试运行一个测试套件,其中在.runsettings文件中定义了数据收集器,而不是使用/enablecodecoverage开关,但这会产生上面列出的JSON错误.

I've tried to run a test suite where the datacollector was defined in a .runsettings file instead of using the /enablecodecoverage switch, but that produces the JSON error listed above.

将本地TFS升级到2017年更新1后,我们能够成功执行单元测试并获得代码覆盖率.

After upgrading our TFS on-premise to 2017 update 1 we we're able to successfully execute our unit tests AND get code coverage.

但是,我们正在使用SonarQube,显然,在编写Marketplace扩展3.0.0版中提供的SonarQube扫描器时,由于VS 2017中注册表项的更改,因此无法正确定位代码覆盖率报告.

We are however using SonarQube and apparently at this time of writing the SonarQube scanner provided in the Marketplace Extension v. 3.0.0 doesn't correctly locate the code coverage report due to the change in registry keys done in VS 2017.

SonarQube已提交了错误报告关于这个问题.

您可以通过在以下注册表项下手动创建一个名为"ShellFolder"的注册表值来解决此限制:

You can get around this limitation by manually creating a registry value named 'ShellFolder' under the follow registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\15.0

然后,"ShellFolder"字符串值应为:

The 'ShellFolder' string value should then be:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise

如果有人遇到与我们相同的问题,我在这里留下了以上信息.

I've left the above information here in case somebody else comes looking with same problems that we had.

推荐答案

原因是,如果直接调用vstest.console.exe工具,则没有/EnableCodeCoverage选项. (为Visual Studio测试步骤/任务分离vstest.console.exe路径).如果通过VS 2017的开发人员命令提示符调用vstest.console命令,则它具有/EnableCodeCoverage.

The reason is that there isn’t /EnableCodeCoverage option if call vstest.console.exe tool directly. (Sepecify vstest.console.exe path for Visual Studio Test step/task). If call vstest.console command through Developer Command Prompt for VS 2017, it has /EnableCodeCoverage.

要解决此问题,您可以将TFS 2017升级到 TFS 2017更新1 ,然后选择 2.* 版本的 Visual Studio Test步骤/任务,然后您可以为 VSTest版本选择 Visual Studio 2017 选项.

To deal with this issue, you can upgrade your TFS 2017 to TFS 2017 update 1, then select 2.* version of Visual Studio Test step/task, after that you can select Visual Studio 2017 option for VSTest version.

更新:

另一种解决方法是,您可以安装 VS 2017代理(适用于Visual Studio 2017的工具),然后在Visual Studio测试步骤/任务的测试代理安装文件夹中指定vstest.console.exe路径. (C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ TestAgent \ Common7 \ IDE \ CommonExtensions \ Microsoft \ TestWindow \ vstest.console.exe)

Another workaround is that, you can install agent for VS 2017 (Tools for Visual Studio 2017) on build agent, then specify vstest.console.exe path in test agent installation folder for Visual Studio Test step/task. (C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe)

这篇关于如果启用了代码覆盖率,则TFS 2017测试任务在VS 2017构建计算机上运行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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