简体   繁体   English

NUnit无法加载MSTestAdapter / MSTestFramework DLL,并且“无法找到任何测试”

[英]NUnit failed to load MSTestAdapter/MSTestFramework DLLs and “couldnt find any tests”

I am doing a unit test with NUnit and i want to integrate it into azure devops. 我正在使用NUnit进行单元测试,我想将其集成到天蓝色的devops中。 When i run the test locally in visual studios with test explorer, the tests are able to run properly without failure. 当我在带有测试资源管理器的视觉工作室中本地运行测试时,测试能够正常运行而不会失败。

However, when i build it on azure devops, i encounter the problem of NUnit failing to load the MSTestAdapter and MSTestFramework Dlls or it being unable to find MSTestAdapter/MSTestFramework dlls. 但是,当我在azure devops上构建它时,遇到NUnit无法加载MSTestAdapter和MSTestFramework DLL或无法找到MSTestAdapter / MSTestFramework dll的问题。

Initially when i looked through, i thought it was because my processor architecture did not match.Thus i tried to create a runsettings file and change the test platform to x64 for NUnit to match the test. 最初浏览时,我以为是因为我的处理器体系结构不匹配,因此我试图创建一个runsettings文件并将NUnit的测试平台更改为x64以匹配测试。 However, it still didnt work and gave me the same error message (will be shown below) 但是,它仍然无法正常工作,并给了我相同的错误消息(如下所示)

code in Runsettings file which i have tried : 我尝试过的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

What is the framework version and visual studio version of the NUnit project? NUnit项目的框架版本和Visual Studio版本是什么?

In the "visual studio test" task, you can select the visual studio version. 在“ Visual Studio测试”任务中,可以选择Visual Studio版本。

Maybe the version of the NUnit Project is higher than the version of the task. 也许NUnit Project的版本高于任务的版本。

You can specify the path of the vstestconsole if that is the case. 在这种情况下,您可以指定vstestconsole的路径。

The error indicated “Could not load type 'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope' from assembly 'Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0 …” 错误指示“无法从程序集“ Microsoft.VisualStudio.TestPlatform.TestFramework,版本= 14.0.0.0…加载类型'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope”。”

As 'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope' only applies to MSTest.TestFrameWork.1.3.2 or higher. 由于“ Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope”仅适用于MSTest.TestFrameWork.1.3.2或更高版本。 Your test project might reference to the wrong assembly. 您的测试项目可能引用了错误的程序集。

Both of the package MSTest.TestAdapter.1.3.2 and package Microsoft.VisualStudio.TestPlatform.14.0.0 have Microsoft.VisualStudio.TestPlatform.TestFramework assembly. 程序包MSTest.TestAdapter.1.3.2和程序包Microsoft.VisualStudio.TestPlatform.14.0.0都具有Microsoft.VisualStudio.TestPlatform.TestFramework程序集。 But only the one in package MSTest.TestAdapter.1.3.2 have 'Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope 但只有MSTest.TestAdapter.1.3.2包中的一个具有“ Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope”

You can try to point your “Microsoft.VisualStudio.TestPlatform.TestFramework” reference to the folder where MSTest.TestFramework.1.3.2 resides in your test csproj file. 您可以尝试将“ Microsoft.VisualStudio.TestPlatform.TestFramework”引用指向测试csproj文件中MSTest.TestFramework.1.3.2所在的文件夹。

In my own .net framework test project I changed the value of tag "HintPath" which resides under tag "reference Microsoft.VisualStudio.TestPlatform.TestFramework….." like below: 在我自己的.net Framework测试项目中,我更改了标记“ 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>

Apparently there was something wrong with my visual studios. 我的视觉工作室显然出了点问题。 Not very sure which part of my vs it was that affected my testing, but after reinstalling vs and building from scratch, i am able to build on devops without any error. 不是很确定我的vs的哪一部分会影响我的测试,但是在重新安装vs并从头开始构建之后,我能够在devops上构建而没有任何错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM