简体   繁体   中英

Xunit Unit Tests will not run

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?

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

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.

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.

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.

关闭并重新打开 Visual Studio 对我有用。

If you have a project running on the same Visual Studio (or any other instance of Visual Studio), please stop it. Although I know it's awkward, it solved the problem.

I had same issue, I installed below nuget packages

 <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
  <PackageReference Include="xunit" Version="2.4.1" />
  <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">

If your issue in Visual Studio is that the Test Runner output seems empty, check that the relevant buttons (white boxes, below) are all selected.

检查白框

Encountered this problem on VS 2019 recently. Installing VS.QualityTools.UnitTestFramework nuget fixed the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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