microsoft / vstest

Visual Studio Test Platform is the runner and engine that powers test explorer and vstest.console.
MIT License
884 stars 319 forks source link

.NET Core xunit projects skip all found tests #1220

Closed JoyceLiang closed 6 years ago

JoyceLiang commented 6 years ago

Description

.NET Core xunit projects skip all found tests

Steps to reproduce

  1. Create xUnit Text Project (.NET Core)
  2. Goto csproj file, change the TargetFramework to net461

Expected behavior

Click "Run All" from Text Explorer can run all exist tests.

Actual behavior

untitled

Found the test but skip running.

Diagnostic logs

[10/24/2017 10:07:06 AM Informational] ========== Discover test finished: 1 found (0:00:01.3983067) ========== [10/24/2017 10:07:09 AM Informational] ------ Run test started ------ [10/24/2017 10:07:09 AM 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. [10/24/2017 10:07:10 AM Warning] [xUnit.net 00:00:00.0280058] Skipping: XUnitTestProject1 (could not find dependent assembly 'Microsoft.Extensions.DependencyModel, Version=1.1.0') [10/24/2017 10:07:10 AM Warning] No test is available in d:\temp\XUnitTestProject1\XUnitTestProject1\bin\Debug\net462\XUnitTestProject1.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again. [10/24/2017 10:07:10 AM Informational] ========== Run test finished: 0 run (0:00:00.6139526) ==========

Environment

VS 15.5.0 Preview 2.0 [27019.0.d15rel] Operating system, Win 10 Build version of vstest.console 15.5.0-preview-20171016-02

codito commented 6 years ago

@JoyceLiang both the .NET Core and .NET Full adapters are getting loaded in test runner (this is most likely same issue as https://github.com/Microsoft/vstest/issues/811). Can you please try latest xunit adapter 2.3.x?

JoyceLiang commented 6 years ago

Thank you @codito, xunit 2.3.0 works for me.

kccarter76 commented 3 years ago

this issue has resurfaced:

I have updated to 2.4.3, I am unable to run any of the discovered tests in xunit, I have changed through all the options for the processor architecture for AnyCPU Projects. I have provided snap shots for all the screens.

image image image image

here is the package config

packages.config.txt

Sanan07 commented 3 years ago

@kccarter76 Did you try some workarounds from here? And could you please run your test with diag and get logs there and share with us.

kccarter76 commented 3 years ago

here is the diagnostic output unittest.host.21-01-18_12-35-26_57056_1.log

I noticed quite a few file not found errors in regards to the microsoft.testplatform I tried adding the nuget package of the same name. no change.

Visual Studio 2019 enterprise was a fresh install of visual studio after windows 10 reset of the system drive.

Sanan07 commented 3 years ago

By the logs, it seems that some dll from Test Platform are missing. Can you update Microsoft.Net.Test.SDK in your project to latest one and test it? Is it any other log file did you get from \diag option? It should generate two diagnostic log files, if you have please share that one as well.

kccarter76 commented 3 years ago

here is the new log after adding Microsoft.Net.Test.SDK nuget.

unittest.host.21-01-18_17-18-58_00803_1.log packages.config.txt

the log still has these errors: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Diagnostics.NETCore.Client' System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.TestPlatform.TestHostRuntimeProvider' System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.TestPlatform.Extensions.BlameDataCollector'

is there a reason why it is using net 5 when running unit tests for .net 4.5.2?

Sanan07 commented 3 years ago

@kccarter76 That is the problem, dotnet test runs on net 5.0 and you probably do not have it installed. It tries to load these dlls : "C:\Program Files\dotnet\sdk\5.0.102\Extensions\Microsoft.Diagnostics.NETCore.Client.dll", "C:\Program Files\dotnet\sdk\5.0.102\Extensions\Microsoft.TestPlatform.Extensions.BlameDataCollector.dll", "C:\Program Files\dotnet\sdk\5.0.102\Extensions\Microsoft.TestPlatform.Extensions.EventLogCollector.dll", "C:\Program Files\dotnet\sdk\5.0.102\Extensions\Microsoft.TestPlatform.TestHostRuntimeProvider.dll", "C:\Program Files\dotnet\sdk\5.0.102\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger.dll", "C:\Program Files\dotnet\sdk\5.0.102\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.dll",

and fails. So install latest net 5.0 and try again.

nohwnd commented 3 years ago

@Sanan07 I don't think that is the problem. This looks like a more generic problem with the extensions resolving. I see that same assembly errors even on run that passes all tests. And in dotnet versions going back to at least 3.0.301/

Imho this is the actual error: could not find dependent assembly 'Microsoft.AspNet.OData.Test, Version=7.5.4')

TpTrace Information: 0 : 13364, 12, 2021/01/18, 12:35:27.309, 2428221805554, testhost.net452.x86.exe, AssemblyResolver.OnResolve: Resolved assembly: xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, from path: D:\Users\Kenneth.Carter\Documents\WebApi\bin\Debug\UnitTest\AspNet\xunit.abstractions.dll TpTrace Warning: 0 : 13364, 12, 2021/01/18, 12:35:27.554, 2428224251754, testhost.net452.x86.exe, [xUnit.net 00:00:00.35] Skipping: Microsoft.AspNet.OData.Test (could not find dependent assembly 'Microsoft.AspNet.OData.Test, Version=7.5.4') TpTrace Verbose: 0 : 13364, 12, 2021/01/18, 12:35:27.554, 2428224253392, testhost.net452.x86.exe, TestRequestHandler.SendData: sending data from testhost: {"Version":3,"MessageType":"TestSession.Message","Payload":{"MessageLevel":1,"Message":"[xUnit.net 00:00:00.35] Skipping: Microsoft.AspNet.OData.Test (could not find dependent assembly 'Microsoft.AspNet.OData.Test, Version=7.5.4')"}} TpTrace Verbose: 0 : 13364, 3, 2021/01/18, 12:35:27.561, 2428224321486, testhost.net452.x86.exe, BaseRunTests.RunTestInternalWithExecutors: Completed running tests for executor://xunit/VsTestRunner2/net TpTrace Warning: 0 : 13364, 3, 2021/01/18, 12:35:27.563, 2428224335596, testhost.net452.x86.exe, No test is available in D:\Users\Kenneth.Carter\Documents\WebApi\bin\Debug\UnitTest\AspNet\Microsoft.AspNet.OData.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

@kccarter76 please make sure that this assembly will end up in your bin folder. Usually this problem happens when you have a nuget dependency that does not get included in the test project build. And you can usually fix it by installing the appropriate nuget package directly to the test project.

kccarter76 commented 3 years ago

@Sanan07 I have 5.0.102 installed, which is the most current version available.

@nohwnd the file xunit.abstractions.dll is in the bin folder for the AspNet project. it is version 2.0.3 dated 8/25/2018 7:54 pm

kccarter76 commented 3 years ago

image image

nohwnd commented 3 years ago

Yeah I just realized the dll you are supposed to be missing is the same as your test dll. So either you are referencing the version 7.5.4 of the same-named assembly in your test assembly (can happen when ctrl+dot or alt enter completion goes wrong), or I don't know :D Maybe enabling fusion logs could help? (or this tool https://github.com/awaescher/Fusion)

kccarter76 commented 3 years ago

here is the diag with fusion logging enabled.

unittest.host.21-01-19_10-34-22_07554_1.log

I have traced every file path mentioned and there is a file at the end of each of those paths with the name of the file that is receiving the exception file not found. I have no idea why this happening. I am at point where I wish I could roll back my visual studio to a version that is pre net 5. because, I had earlier iteration with VS 2019 where I could run these unit tests using x64 processor architecture. I think it was 16.4 or 16.5.