Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run Xunit tests on Visual Studio 2017

Can't run all the XUnit tests on my Visual Studio 2017. Version 15.6.4

They can be viewed in TestExploer and when I run them from there I get something like this:

[27.03.2018 12:21:46 Informational] ------ Load Playlist started ------
[27.03.2018 12:21:46 Informational] ========== Load Playlist finished 
(0:00:00,0215566) ==========
[27.03.2018 12:22:27 Informational] Executing test method 'Lebara.Remittance.Test.ServiceImplementation.RiskEngineServiceTest.ShouldTest'
[27.03.2018 12:22:27 Informational] ------ Run test started ------
[27.03.2018 12:22:29 Warning] 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.
[27.03.2018 12:22:29 Warning] [xUnit.net 00:00:00.0209459] Skipping: 
Lebara.Remittance.Test (could not find dependent assembly 
'Microsoft.Extensions.DependencyModel, Version=1.1.0')
[27.03.2018 12:22:29 Warning] No test is available in C:\ReposNew\Lebara.Remittance\Lebara.Remittance\Lebara.Remittance.Test\bin\Debug\Lebara.Remittance.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[27.03.2018 12:22:29 Informational] ========== Run test finished: 0 run 
(0:00:02,1543479) ==========
[27.03.2018 12:34:19 Informational] Executing test method 'Lebara.Remittance.Test.ServiceImplementation.RiskEngineServiceTest.ShouldTest'
[27.03.2018 12:34:19 Informational] ------ Run test started ------
[27.03.2018 12:34:20 Warning] 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.
[27.03.2018 12:34:20 Warning] [xUnit.net 00:00:00.0200861] Skipping: 
Lebara.Remittance.Test (could not find dependent assembly 
'Microsoft.Extensions.DependencyModel, Version=1.1.0')
[27.03.2018 12:34:20 Warning] No test is available in C:\ReposNew\Lebara.Remittance\Lebara.Remittance\Lebara.Remittance.Test\bin\Debug\Lebara.Remittance.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[27.03.2018 12:34:20 Informational] ========== Run test finished: 0 run 
(0:00:00,7088116) ==========

I tried deleting %TEMP%\VisualStudioTestExplorerExtensions - nothing helped.

The thing is, several days ago I could run them. I did not change a thing. Just have no idea what is going on.

Also I had this warning

 [27.03.2018 12:22:29 Warning] 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.
 [27.03.2018 12:22:29 Warning] [xUnit.net 00:00:00.0209459] Skipping: 
 Lebara.Remittance.Test (could not find dependent assembly 
 'Microsoft.Extensions.DependencyModel, Version=1.1.0')
like image 928
Rostyslav Fedyk Avatar asked Mar 27 '18 09:03

Rostyslav Fedyk


2 Answers

I had problems with xUnit. Some important things:

1) Make sure the "Microsoft Visual Studio Test Platform" extension is enabled

2) Make sure "Test => Test Settings => Default Processor Architecture" matches your build.

3) Install nuget package 'xunit.runner.visualstudio'

like image 144
FrankyHollywood Avatar answered Sep 23 '22 10:09

FrankyHollywood


If you are using .NET Core or ASP.NET Core, then from xunit (https://xunit.github.io/docs/getting-started-dotnet-core.html):

Running tests with Visual Studio

If you're having problems discovering or running tests, you may be a victim of a corrupted runner cache inside Visual Studio. To clear this cache, shut down all instances of Visual Studio, then delete the folder %TEMP%\VisualStudioTestExplorerExtensions. Also make sure your solution is only linked against a single version of the Visual Studio runner NuGet package (xunit.runner.visualstudio).

If you have Visual Studio Community (or a paid-for version of Visual Studio), you can run your xUnit.net tests within Visual Studio's built-in test runner (named Test Explorer). Unfortunately, this does not include Express editions of Visual Studio (you should upgrade to the free Community Edition instead).

Right click on the project in Solution Explorer and choose Manage NuGet Packages. You will need to install two packages:

xunit.runner.visualstudio (version 2.3.1 or later)
Microsoft.NET.Test.Sdk (version 15.0.0 or later; we recommend using whatever the latest RTM build is)

Make sure Test Explorer is visible (go to Test > Windows > Test Explorer). Every time you build your project, the runner will discover unit tests in your project. After a moment of discovery, you should see the list of discovered tests:

Click the Run All link in the Test Explorer window, and you should see the results update in the Test Explorer window as the tests are run:

You can click on a failed test to see the failure message, and the stack trace. You can click on the stack trace lines to take you directly to the failing line of code.

Also mentions

Running tests against multiple targets

(if some projects target Core and others target .NET 4.5 for example.)

Another possibility:

Ensure using xunit 2.3.0+

like image 39
Steve Padmore Avatar answered Sep 22 '22 10:09

Steve Padmore