【问题标题】:How do I configure target framework for VSTest 2015 to run a unit test built to use .net 4.6.1?如何为 VSTest 2015 配置目标框架以运行使用 .net 4.6.1 构建的单元测试?
【发布时间】:2019-03-07 17:56:02
【问题描述】:

我正在尝试将 TeamCity 配置为使用 Visual Studio 2015 的 VSTest.console.exe 运行我的单元测试。

对测试运行器有效的唯一选项(即使在 .runsettings 文件中)是:

<!-- Framework35 | [Framework40] | Framework45 -->

我的 .runsettings 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <!-- Configurations that affect the Test Framework -->
  <RunConfiguration>
    <MaxCpuCount>1</MaxCpuCount>
    <!-- Path relative to solution directory -->
    <ResultsDirectory>.\TestResults</ResultsDirectory>

    <!-- [x86] | x64  
      - You can also change it from menu Test, Test Settings, Default Processor Architecture -->
    <TargetPlatform>x86</TargetPlatform>

    <!-- Framework35 | [Framework40] | Framework45 -->
    <TargetFrameworkVersion>Framework45</TargetFrameworkVersion>

    <!-- Path to Test Adapters -->
    <TestAdaptersPaths>%SystemDrive%\Temp\foo;%SystemDrive%\Temp\bar</TestAdaptersPaths>
  </RunConfiguration>
</RunSettings>

当我将它设置为 Framework45 时,它告诉我:

[19:17:33][Step 2/2] VSTest executable: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\VSTest.console.exe
[19:17:33][Step 2/2] Command line params: [[Y:\TeamCity\BuildAgent1\work\f1cf88fd0bf6555\Javelin.Identity.Tests\bin\x64\Integration\Javelin.Identity.Tests.dll] [/Settings:test.runsettings] [/Logger:trx] [/Platform:x86]]
[19:17:33][Step 2/2] Starting: C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.NUnitLauncher.exe #TeamCityImplicit
[19:17:33][Step 2/2] in directory: Y:\TeamCity\BuildAgent1\work\f1cf88fd0bf6555
[19:17:33][Step 2/2] JetBrains dotCover Console Runner 10.0.2. Build 104.0.20151218.125453
[19:17:33][Step 2/2] Copyright (c) 2009-2016 JetBrains s.r.o. All rights reserved.
[19:17:34][Step 2/2] [JetBrains dotCover] Coverage session started [3/1/2016 7:17:34 PM]
[19:17:38][Step 2/2] Microsoft (R) Test Execution Command Line Tool Version 14.0.24720.0
[19:17:38][Step 2/2] Copyright (c) Microsoft Corporation.  All rights reserved.
[19:17:38][Step 2/2] 
[19:17:39][Step 2/2] Starting test execution, please wait...
[19:17:39][Step 2/2] Test run will use DLL(s) built for framework Framework45 and platform X86. Following DLL(s) will not be part of run: 
[19:17:39][Step 2/2] Javelin.Identity.Tests.dll is built for Framework None and Platform X64.
[19:17:39][Step 2/2]  Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
[19:17:39][Step 2/2] Error: None of the provided test containers match the Platform Architecture and .Net Framework settings for the test run. Platform: X86  .Net Framework: Framework45. Go to http://go.microsoft.com/fwlink/?LinkID=330428 for more details on managing these settings.
[19:17:39][Step 2/2] 

当我将它设置为 Framework46 时,它告诉我:

[步骤 2/2] 错误:加载设置时出错。 错误:设置“RunConfiguration”无效。无效值“Framework46” 为“TargetFrameworkVersion”指定..

这甚至应该适用于 4.6.1 吗?

【问题讨论】:

  • 我确实发现,当我在命令提示符下使用这个 testrunner 运行 vstest.console.exe 时,问题似乎是它是如何从团队城市运行的。

标签: .net unit-testing teamcity vstest .net-4.6.1


【解决方案1】:

您可以将 .RunSettings 文件中 TargetFrameworkVersion 的值设置为以下内容:
.NETFramework,Version=v4.6.1

我知道这具有误导性,因为他们在 here 中的文档
我通过查看 vstest.console.exe

的帮助命令发现了这个
vstest.console.exe /?

其中包括:

--Framework|/Framework:<Framework Version>
  Target .Net Framework version to be used for test execution.
  Valid values are ".NETFramework,Version=v4.5.1", ".NETCoreApp,Version=v1.0" etc.
  Other supported values are Framework35, Framework40, Framework45 and FrameworkCore10.

然后我尝试使用这些值中的任何一个,它都起作用了。就我而言,它是 .NET 4.5.2

.RunSettings 文件的示例如下:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <!-- Configurations that affect the Test Framework -->
  <RunConfiguration>
    <!-- Path relative to solution directory -->
    <ResultsDirectory>.\TestResults</ResultsDirectory>

    <!-- [x86] | x64  
      - You can also change it from menu Test, Test Settings, Default Processor Architecture -->
    <TargetPlatform>x64</TargetPlatform>

    <!-- Framework35 | [Framework40] | Framework45 -->
    <TargetFrameworkVersion>.NETFramework,Version=v4.5.2</TargetFrameworkVersion>
  </RunConfiguration>

  <!-- Configurations for data collectors -->
  <DataCollectionRunSettings>
    <DataCollectors>


    </DataCollectors>
  </DataCollectionRunSettings>

  <!-- Adapter Specific sections -->

  <!-- MSTest adapter -->
  <MSTest>  
    <MapInconclusiveToFailed>True</MapInconclusiveToFailed>  
    <CaptureTraceOutput>false</CaptureTraceOutput>  
    <DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>  
    <DeploymentEnabled>False</DeploymentEnabled>  
    <AssemblyResolution>  
      <Directory path=".\bin" includeSubDirectories="false"/>  
    </AssemblyResolution>  
  </MSTest>  
</RunSettings>

【讨论】:

  • 对我不起作用。在 VS2017 中,我在测试输出窗口中收到以下错误:[2018 年 7 月 6 日上午 9:48:38 错误] 无法配置运行设置插件“VSTest 运行配置”的设置,因为它引发了以下异常:“加载时发生错误设置。错误:设置“RunConfiguration”无效。为 'TargetFrameworkVersion' 指定的值无效 '.NETFramework,Version=v4.6.1'..' 请联系插件作者。
  • 希望使用示例文件,只要您不会再出现该错误
【解决方案2】:

这是在 vstest.console 中确认的known issue。您可以尝试问题中提出的解决方法(通过runsettings文件指定框架,并将'Framework'参数值保留为默认值)

【讨论】:

  • 不幸的是,我尝试了这种解决方法,但在从 TeamCity 运行时它不起作用。我在上面的问题中添加了更多细节以反映这一点。
  • 这就是为什么您应该始终复制链接的相关部分而不是发布仅链接的答案:MS Connect 站点已停用,现在无法获得答案...
猜你喜欢
  • 1970-01-01
  • 2020-03-05
  • 2020-08-13
  • 2014-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-05
相关资源
最近更新 更多