Xunit Unit Tests will not run
Asked Answered
A

10

45

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?

Arrest answered 19/12, 2017 at 20:34 Comment(0)
S
46

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.

Sphygmograph answered 19/1, 2018 at 3:11 Comment(4)
The official documentation obviously wasn't tested: github.com/dotnet/samples/tree/master/core/getting-started/…Stidham
However this trick doesn't work in Visual Studio 2017 for .net core projectsDeceitful
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> fix it.Thumb
The Microsoft.NET.Test.Sdk was required in VS 2022 with .net 6 and xunit. I also added xunit.runner.visualstudio.Lomax
S
62

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

Seamaid answered 28/3, 2018 at 4:27 Comment(1)
You saved my time, I moved from MS Tests to xunit and it was showing message "tests are not discovered".. adding xunit.runner.visualstudio, solved my issue.. Thanks !Nubble
S
46

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.

Sphygmograph answered 19/1, 2018 at 3:11 Comment(4)
The official documentation obviously wasn't tested: github.com/dotnet/samples/tree/master/core/getting-started/…Stidham
However this trick doesn't work in Visual Studio 2017 for .net core projectsDeceitful
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> fix it.Thumb
The Microsoft.NET.Test.Sdk was required in VS 2022 with .net 6 and xunit. I also added xunit.runner.visualstudio.Lomax
E
13

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.

Eldrid answered 25/1, 2018 at 14:33 Comment(2)
Do you have netcore project ?Deceitful
@Deceitful - yes, I do. The OP suggests also .NET Core also due to project.json.Eldrid
A
5

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.

Abstruse answered 20/7, 2018 at 19:48 Comment(4)
Actually my assemblies are all for "Any CPU"Deceitful
And also I changed these default Architectures! Nothing helpsDeceitful
All of my assemblies are also 'Any CPU'. Unfortunately, I never found a real reason for the issue. :-(Abstruse
Seems, this issue from Visual Studio, and faster just to reinstall it.Deceitful
P
0

Close and reopen Visual Studio works for me.

Prytaneum answered 7/6, 2020 at 20:48 Comment(0)
K
0

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.

Knotts answered 7/5, 2021 at 16:51 Comment(0)
B
0

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.

Check the white boxes

Bertilla answered 20/3, 2022 at 15:53 Comment(0)
D
0

Well, I was having the same issue. Maybe it's not the same that we are both facing. But I figured for my issue I was sending the ".exe" String into one of my parameters which somehow could not find any Tests.

Issue Cmd:

dotnet.exe test "K:\ProjectName.csproj" --filter "FullyQualifiedName~Krishnas.Test.UpgradePortal&FullyQualifiedName~C211703" -e BaseUrl="SeleniumURL" -e Username="Username" -e Password="passowrd" -e PatchName="SamplePatch" -e Type="Both" -e Description="Test description" -e PatchFileDownload="C211703.exe" -v n --logger trx

Worked Command.

dotnet.exe test "K:\ProjectName.csproj" --filter "FullyQualifiedName~Krishnas.Test.UpgradePortal&FullyQualifiedName~C211703" -e BaseUrl="SeleniumURL" -e Username="Username" -e Password="passowrd" -e PatchName="SamplePatch" -e Type="Both" -e Description="Test description" -e PatchFileDownload="C211703" -v n --logger trx
Destination answered 11/7, 2024 at 21:1 Comment(0)
H
-1

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">
Heft answered 23/7, 2021 at 15:50 Comment(1)
How does your answer differ or add value to the accepted answer? Or this answer? Or this one? Other than version numbers your answer is basically identical, so edit an existing answer if you have value to add, or consider not answering if you've got nothing new.Printmaking
P
-1

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

Protamine answered 11/8, 2021 at 2:44 Comment(1)
Wlecome to the site! What you suggested has already been covered in at least three or four answers on this question, so consider upvoting one of the existing answers rather than effectively repeating what has already been said.Printmaking

© 2022 - 2025 — McMap. All rights reserved.