【问题标题】:NUnit failed to load MSTestAdapter/MSTestFramework DLLs and "couldnt find any tests"NUnit 无法加载 MSTestAdapter/MSTest 框架 DLL 并且“找不到任何测试”
【发布时间】:2019-12-14 06:13:24
【问题描述】:

我正在使用 NUnit 进行单元测试,我想将它集成到 azure devops 中。 当我使用测试资源管理器在视觉工作室本地运行测试时, 测试能够正常运行而不会失败。

但是,当我在 azure devops 上构建它时,我遇到了 NUnit 无法加载 MSTestAdapter 和 MSTestFramework Dll 或无法找到 MSTestAdapter/MSTestFramework dll 的问题。

最初当我查看时,我认为这是因为我的处理器架构不匹配。因此我尝试创建一个运行设置文件并将测试平台更改为 x64 以使 NUnit 匹配测试。 但是,它仍然没有工作,并给了我同样的错误信息(如下所示)

我尝试过的 Runsettings 文件中的代码:

    ```` <RunSettings>
     ````<!-- Configurations that affect the Test Framework -->
     ```` <RunConfiguration>
        ````<TargetPlatform>x64</TargetPlatform>
     ````   <TargetFrameWorkVersion>Framework45</TargetFrameWorkVersion>
     ```` </RunConfiguration>
    ```` </RunSettings>


Just a part of the error messages
The error message is what i get at the VSTest part in azure devops when i build my project

(the messages are all similar) :

Multiple versions of same extension found. Selecting the highest version.
  Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter : 14.0.2505.1
Input string was not in a correct format.
Could not load type 'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope' from assembly 'Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Could not load type 'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope' from assembly 'Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Unable to load types from the test source 'd:\a\1\s\MSTest.TestAdapter.1.3.2\build\_common\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll'. Some or all of the tests in this source may not be discovered.
Input string was not in a correct format.
Unable to load types from the test source 'd:\a\1\s\MSTest.TestAdapter.1.3.2\build\uap10.0\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll'. Some or all of the tests in this source may not be discovered.
Input string was not in a correct format.
NUnit Adapter 3.12.0.0: Test execution started
Running all tests in d:\a\1\s\HeyX.UnitTest\bin\Debug\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll
   NUnit failed to load d:\a\1\s\HeyX.UnitTest\bin\Debug\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll
Running all tests in d:\a\1\s\HeyX.UnitTest\bin\Debug\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll
   NUnit couldn't find any tests in d:\a\1\s\HeyX.UnitTest\bin\Debug\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll
Running all tests in d:\a\1\s\HeyX.UnitTest\bin\Debug\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
   NUnit couldn't find any tests in d:\a\1\s\HeyX.UnitTest\bin\Debug\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll

【问题讨论】:

    标签: c# selenium azure-devops nunit mstest


    【解决方案1】:

    错误指示“无法从程序集 'Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0 ... 加载类型 'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope' ...”

    作为 'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope' 仅适用于 MSTest.TestFrameWork.1.3.2 或更高版本。您的测试项目可能引用了错误的程序集。

    包 MSTest.TestAdapter.1.3.2 和包 Microsoft.VisualStudio.TestPlatform.14.0.0 都有 Microsoft.VisualStudio.TestPlatform.TestFramework 程序集。但只有包 MSTest.TestAdapter.1.3.2 中的一个具有 'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope

    您可以尝试将“Microsoft.VisualStudio.TestPlatform.TestFramework”引用指向测试 csproj 文件中 MSTest.TestFramework.1.3.2 所在的文件夹。

    在我自己的 .net 框架测试项目中,我更改了标签“HintPath”的值,该标签位于标签“reference Microsoft.VisualStudio.TestPlatform.TestFramework.....”下,如下所示:

    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> 
     <HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
     </Reference>
     <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">        
    <HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
     </Reference>
    

    【讨论】:

      【解决方案2】:

      NUnit项目的framework版本和visual studio版本是多少?

      在“Visual Studio 测试”任务中,可以选择 Visual Studio 版本。

      可能是 NUnit Project 的版本高于任务的版本。

      如果是这种情况,您可以指定 vstestconsole 的路径。

      【讨论】:

      • 嗨 Paulo,我不确定我是否理解,但我相信目标框架版本都设置为 net45(?)
      • 不确定这是否有助于解决问题:测试运行将使用为框架 .NETFramework、Version=v4.0 和平台 X86 构建的 DLL。以下 DLL 与框架/平台设置不匹配。Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll 是为 Framework 4.5 和平台 AnyCPU 构建的。 Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll 是为 Framework 4.5 和 Platform AnyCPU 构建的。 Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll 是为 Framework 4.5 和 Platform AnyCPU 构建的。
      • 你说在本地,一切都很好,但在 azure devops 中,一切都错了,你给出的错误。 !Example, Visual studio task。这是一个示例的屏幕截图,您可以在其中更改测试任务的 Visual Studio 版本。我认为您正在使用它进行测试?
      • 显然我的视觉工作室出了点问题。不太确定我的 vs 的哪一部分影响了我的测试,但是在重新安装 vs 并从头开始构建之后,我能够在 devops 上构建而没有任何错误。谢谢!
      【解决方案3】:

      显然我的视觉工作室出了点问题。不太确定我的 vs 的哪一部分影响了我的测试,但是在重新安装 vs 并从头开始构建之后,我能够在 devops 上构建而不会出现任何错误。

      【讨论】:

      • 解决了错误真是太好了!您可以将您的回复标记为答案!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      相关资源
      最近更新 更多