nunit / nunit3-vs-adapter

NUnit 3.0 Visual Studio test adapter for use under VS 2012 or later
https://nunit.org
MIT License
203 stars 105 forks source link

How to ignore .NET Core test assemblies in the same solution #232

Open msitms opened 7 years ago

msitms commented 7 years ago

Running NUnit tests in "classic" (MSBuild/.csproj-based) .NET test projects using NUnit3TestAdapter works just fine.

Running NUnit tests in .NET Core (dotnet/.xproj-based) test projects using dotnet-test-unit works just fine.

Having both types of test projects in the same solution, it kind of works as well, but I could not find a way to stop NUnit3TestAdapter from trying to run the .NET Core tests in addition to dotnet-test-unit, even though NUnit3TestAdapter is not added to .NET Core test project.

So all my tests in the .NET Core project run twice, once succeeding with dotnet-test-unit, once failing with NUnit3TestAdpater with a BadImageFormatException.

Any idea on how to avoid this? Especially when running server builds using VSTS or TFS?

rprouse commented 7 years ago

Sorry, I can't think of any way to prevent this off the top of my head although the "classic" adapter should ignore the .NET Core projects, so I am going to classify this as a bug. It is likely to become a more common scenario as developers move to .NET Core.

Based on your comments, I assume that the dotnet-test-nunit adapter is working correctly and ignoring the "classic" test projects?

msitms commented 7 years ago

Based on your comments, I assume that the dotnet-test-nunit adapter is working correctly and ignoring the "classic" test projects?

Exactly, it's ignoring the "classic" projects.

My scenario is having a bunch of existing .csproj/MSBuild-based components and NUnit tests, combined with a new ASP.NET Core project exposing the functionality as a web service. We could use e.g. xUnit for testing the ASP.NET Core project, however we would prefer to stick with one unit testing framework.

For VSTS I found a workaround, using the "Test Assembly" filter for the "Visual Studio Test" build step, and running dotnet test as an extra "Command Line" build step for the Core test project.

It's still annoying when testing inside VS since you have always failed tests. Also, when debugging a .NET Core based unit test, VS will start and debug via both test adapters at the same time which is very confusing.

CharliePoole commented 7 years ago

@rprouse We should check to see if this is an engine problem and, if so, whether we have already resolved it for the 3.5 release. I seem to remember that we did this by detecting the use of the portable, sivlerlight and compact framework builds and bypassing the assembly. If it is caused by the engine, we should still hang on to this issue so we can verify that using the new engine fixes it.

rprouse commented 7 years ago

@msitms, I can't reproduce this, either with the VSIX or with the NuGet version of the adapter. Are you using the latest version of the adapter? Do you have the NUnit 2 adapter installed?

image

Here is my test project if you want to try it.

TestVisualStudioAdapter.zip

I am switching this issue to confirm.