CMR
CMR

Reputation: 629

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:

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?

Upvotes: 49

Views: 66651

Answers (10)

Kishan Bheemajiyani
Kishan Bheemajiyani

Reputation: 3439

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

Upvotes: 0

David Bond
David Bond

Reputation: 308

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

Upvotes: 0

Victor Ortenberg
Victor Ortenberg

Reputation: 11

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

Upvotes: -1

Damith Asanka
Damith Asanka

Reputation: 964

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">

Upvotes: 0

Luis Gouveia
Luis Gouveia

Reputation: 8925

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.

Upvotes: 0

Flavio Spedaletti
Flavio Spedaletti

Reputation: 398

Close and reopen Visual Studio works for me.

Upvotes: 1

Pravin
Pravin

Reputation: 979

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

Upvotes: 67

Michael Yanni
Michael Yanni

Reputation: 1566

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.

Upvotes: 5

Alexei - check Codidact
Alexei - check Codidact

Reputation: 23078

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.

Upvotes: 13

Xavier Poinas
Xavier Poinas

Reputation: 19733

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.

Upvotes: 47

Related Questions