nunit3-vs-adapter icon indicating copy to clipboard operation
nunit3-vs-adapter copied to clipboard

TestPlatformException error discovering tests in solution with netstandard extensions library

Open toddlindsey opened this issue 4 years ago • 9 comments

VS2019 16.2.4 NUnit 3.12.0 NUnit3TestAdapter 3.15.1 TestSDK 16.2.0

Start a new solution with a .NET Core (or Net Framework, I don't think it or version matters) project (with nunit+adapter+sdk references) referencing a netstandard2.0 project that contains only the nunit package reference, and build.

Test Discovery phase generates error: Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Unable to find ... NetstandardLib\bin\Debug\netstandard2.0\testhost.dll. Please publish your test project and retry.

The issue here is I need the ability to create various types of re-usable assets that require the NUnit project reference in class libraries that are not themselves test projects. This can be any number of things, including custom NUnit attributes that are applied to tests. It seems the mere presence of the NUnit reference is forcing a test discovery and thus requiring the adapter, which isn't appropriate for a netstandard project (and doesn't work anyway). I also tried setting IsTestProject to false in the csproj, but this did not help.

Let me know if I'm missing something here...

toddlindsey avatar Sep 08 '19 21:09 toddlindsey

Can you please upload a repro project? Make it as small as you can, it should compile "as is".

Without the adapter it should not even try to discover them.

OsirisTerje avatar Sep 09 '19 15:09 OsirisTerje

https://github.com/toddlindsey/NUnitAdapterIssue656

toddlindsey avatar Sep 09 '19 20:09 toddlindsey

(Sorry, notifications stopped coming for some reason. I'll have a look)

OsirisTerje avatar Sep 17 '19 12:09 OsirisTerje

When I run the tests, I see: image But in the console output: image

Since VS is using real time discovery, the standard NUnit discoveryphase is really not needed here (except parts of it is running during execution), but it should in any way not give this response.

And just to be clear, the path is as you described above, to the StandardLib folder: image And, it looks for the testhost.dll, so this is somehow related to how dotnet test works. I'll also contact the PG about this.

@toddlindsey Is what I describe here consistent with what you see ?

OsirisTerje avatar Sep 17 '19 12:09 OsirisTerje

If I add some code to the library and use that in the test, it still works. So I don't think this is a blocker for you. The error message should ofc be fixed in any case. image

The SomeCoolStuff method just returns the parameter, but it is INSIDE the netstandard project, which should be the important thing there.

OsirisTerje avatar Sep 17 '19 13:09 OsirisTerje

Yes the tests run, so not a blocker but following up because of the noise and concern this could be related to discovery times on a very large solution I have to work with, or performing more discoveries than needed because the last one failed.

It seems the real-time discovery works great though; not sure if there is a way to turn off the separate discovery than runs before the tests start?

toddlindsey avatar Sep 17 '19 23:09 toddlindsey

Im getting the same issue - where IsTestProject is just ignored.

Jetski5822 avatar Nov 29 '21 02:11 Jetski5822

@Jetski5822 Not sure I understand what is your issue. Is it the same as above, or do you have a different issue ?

OsirisTerje avatar Nov 29 '21 08:11 OsirisTerje

Ahh yeah, I wasnt really clear @OsirisTerje let me add some details. In my solution, I have a number of projects that have NUnit dependencies to extend the existing functionality of NUnit, but those projects themselves are not test projects. So, I mark these projects with

<IsTestProject>false</IsTestProject>

The issue here is that these projects still show one of three errors when discovering tests

First:

Test project SomeCompany.UnitTests.Data.Oracle.Common does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project.
It's recommended to reference NuGet test adapters in each test project in the solution.

Second

No test is available in C:\code\disco\dotnet-shared\src\SomeCompany.Components\SomeCompany.Components.Planning.Test.Utilities\bin\Debug\net5.0\SomeCompany.Components.Planning.Test.Utilities.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Third

Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Unable to find ... NetstandardLib\bin\Debug\netstandard2.0\testhost.dll
^^ Same as the original poster

Just because you have NUnit referenced doesnt mean there are tests in the project; especially given that we are overriding the IsTestProject attribute from the Test.Sdk.

Thoughts?

Jetski5822 avatar Nov 29 '21 08:11 Jetski5822