Xunit Unit Tests will not run

杀马特。学长 韩版系。学妹 提交于 2019-12-22 01:27:16

问题


I am completely stuck on this issue. So my team has a unit test project in a services test project. The tests are discovered in the test explorer pane however when I try and run the tests I get these errors:

'Multiple test adapters with the same uri 'executor://xunit/VsTestRunner2' were found. Ignoring adapter 'Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner'. Please uninstall the conflicting adapter(s) to avoid this warning'

'[xUnit.net 00:00:00.0251250] Skipping: (could not find dependent assembly 'Microsoft.Extensions.DependencyModel, Version=1.1.0')'

'No test is available in C:\. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.'

Context information:

  • Xunit 2.2.0
  • Visual Studio 15.5.2
  • Windows 10 1709 Build: 16299.125

My Test Projects project.json:

{
   "version": "1.0.0-*",
   "testRunner": "xunit",
    "dependencies": {
       "dotnet-test-xunit": "2.2.0-preview2-build1029",
       "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.1.3",
       "Microsoft.DiaSymReader": "1.0.8",
       "Microsoft.DiaSymReader.Native": "1.4.1",
       "Microsoft.Extensions.Logging.Abstractions": "1.1.2",
       "Microsoft.Extensions.Testing.Abstractions": "1.0.0-preview2-003121",
       "Newtonsoft.Json": "9.0.1",
       "WebServices": "1.0.0-*",
       "xunit": "2.2.0",
       "xunit.abstractions": "2.0.1",
       "xunit.assert": "2.2.0",
       "xunit.core": "2.2.0",
       "xunit.extensibility.core": "2.2.0",
       "xunit.extensibility.execution": "2.2.0",
       "xunit.runner.utility": "2.2.0"
   },
   "frameworks": {
    "net461": {
        "dependencies": {
            "Microsoft.NETCore.Platforms": "1.1.0"
        }
    }
}

The Weird thing is that it works for my team members. But not me. The differences in our environments are: the latest update from Windows and Visual Studio, while they are an update or two behind.

Does anyone know of a workaround?


回答1:


I had the same problem and I fixed it by updating Visual Studio 2017 from 15.5.2 to 15.5.4 and updating my test project references from:

<ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

to:

<ItemGroup>
    <PackageReference Include="xunit" Version="2.3.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>

And restarting Visual Studio (apparently VS caches and uses the previous version even after you've updated).

Not sure if one of the 3 things or the combination of them fixed it.




回答2:


Installing or updating "xunit.runner.visualstudio" package did the trick for me. Until that, it was not working with framework 462.




回答3:


I encountered the same issue, but I have already had Visual Studio 2017 15.5.4 installed. In order to make it work I updated all xunit related references and now my .csproj relevant references look like this:

<ItemGroup>
   <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
   <PackageReference Include="xunit" Version="2.3.1" />
   <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

Not really sure what was not working, but my advice is to make sure that these reference are within csproj and have these minimum versions.




回答4:


I was having a similar issue as yours, stating could not find dependent assembly; when in fact, that assembly was there and available to the xUnit VS runner. However, what the actual issue was, I had Visual Studio set to use the 32bit test runner by default. The 'dependent assembly' it couldn't find was simply a different processor architecture than the xUnit test runner being used.

To fix, as mentioned here, from the Visual Studio menu, go to Test -> Test Settings -> Default Processor Architecture and set that to X64 if you are using 64bit assemblies, or X86 if you are using 32bit assemblies. The error that the xUnit VS runner gives is very misleading to try to debug this issue.

This issue I saw when installing Visual Studio on a new machine. The tests would run on my desktop maching in Visual Studio, but not on my laptop.



来源:https://stackoverflow.com/questions/47894776/xunit-unit-tests-will-not-run

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