Unit tests not detected in Visual Studio 2017

I have been struggling with VS 2017 since I installed it. Now it seems that Unit Tests will only run from the "dotnet test."

My project is .NET Core 1.1.1. I have the SDK installed and update for 1.1.1.

I tried the sample on MSDN ( https://msdn.microsoft.com/en-us/library/ms182532.aspx ), which also fails exactly the same.

All NuGet packages for tests and the main project are current. And both the test project and the main project are built without errors. Tests run successfully from the command line.

Has anyone gotten Unit Tests to launch in VS 2017, if so, how?

Thanks, John




Update - Extension

Here is an example of a simple test project that does not work on GitHub . This is an example with xUnit, but I tried NUnit and a visual studio built into MS tests. No matter what testing or changes I make, I cannot get the VS tester to find any tests.

What i tried

  • Delete cache files VS test DEL %TEMP%\VisualStudioTestExplorerExtensions
  • Restart VS
  • Closing / Opening Test Conductor
  • xUnit has Microsoft.DotNet.InternalAbstractions installed ( see SO post )
  • for NUnit, ensure that the adapter installed is the same version (3) as the NUnit package
  • test -> test settings -> default processor architecture installed in x86

Question
Can anyone suggest a working example of a solution .Net Core 1.1.0 in VS2017 (project files .csproj), where the VS test tester successfully finds unit tests OR show me the problem in the given example.

+191
c # unit-testing visual-studio visual-studio-2017
Mar 17 '17 at 15:52
source share
33 answers
  • one
  • 2

In my case, it turned out that I just had to update my test adapters and test infrastructure. Done.

NuGet Package Manager Example:

enter image description here

+180
Jun 02 '17 at 23:37 on
source share

It just worked for me (I don't know if this is the result of changing damaged workspaces):

Delete VS test cache files in% TEMP% \ VisualStudioTestExplorerExtensions and restart VS2017.

+121
02 Oct '17 at 19:24
source share

The API for test adapters for .NET Core has changed with the release of Visual Studio 2017 and the transition from the project.json format to the csproj format. This made existing dotnet-test-* adapters like dotnet-test-nunit obsolete.

The adapters have been updated, but the way to install and run tests in Visual Studio or on the command line using dotnet test requires different references in your test projects. Beware of any documentation that you find reference packages are in dotnet-test-* format, as they are outdated.

First, your test project should target a specific .NET Framework or .NET Framework. It cannot target .NET Standard , even if the code you are testing is .NET Standard. This is because the purpose of the tests indicates which platform the tests will run on. The .NET Standard is similar to the PCL (Portable Class Library) because it can run on many platforms.

Then you need to add links to Microsoft.NET.Test.Sdk , your test structure and a compatible test adapter. For NUnit, your links will look like this:

 <itemgroup> <packagereference Include="Microsoft.NET.Test.Sdk" Version="15.0.0"></packagereference> <packagereference Include="NUnit" Version="3.7.1"></packagereference> <packagereference Include="NUnit3TestAdapter" Version="3.8.0"></packagereference> </itemgroup> 

The comment above mentions the addition,

 <ItemGroup> <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> </ItemGroup> 

This is not strictly required, but can help. It is automatically added to all unit test projects in Visual Studio to quickly find projects with tests.

If your tests do not appear in Visual Studio, the first thing to try is to close your solution and then open them again. It seems that errors in Visual Studio do not detect changes in projects when they are edited.

See Testing .NET Core with NUnit in Visual Studio 2017 for more information.

+55
May 16 '17 at 12:30
source share

I had the same issue and got it by following these steps:

  • First close all open instances of Visual Studio and delete this folder:% TEMP% \ VisualStudioTestExplorerExtensions. ( Running tests using Visual Studio )
  • First go to the Nuget package manager and install Microsoft.NET.Test.Sdk (15.3.0-preview-20170425-07), and then install xunit.runner.visualstudio (2.3.0-beta1-build1309). See the attached Nuget screenshot to see all the packages I had to install in order to get the latest VS 2017 versions to discover my tests. Nuget Screenshot
+38
Apr 26 '17 at 15:00
source share

Forgetting to make the test class publicly available to prevent detection of test methods inside

I had the xUnit project by default and removed the UnitTest1.cs sample, replacing it with the controller test class using several tests, but none were found

In short, after updating the xUnit, Test.Sdk, xUnit.runner packages and restoring the project, I encountered a build error:

Error xUnit1000 Test classes must be public

Fortunately, the updated version threw this exception to save me any problems.

Changing the test class to publicly fix my problem

+23
Nov 29 '17 at 14:19
source share

In my case, I aimed the test project at x64 Architecture, and for the parameter Architecture Architecture (test-> Default Processor Architecture) the value x86 was changed. They did not match.

After you set the factory default Architecture to x64 and recreate all the tests, they were discovered again.

+10
Nov 23 '17 at 11:19 on
source share

Do not read obsolete articles under MSDN. Related .NET Core materials are at docs.microsoft.com

https://docs.microsoft.com/en-us/dotnet/articles/core/testing/

Generally speaking, you need a .NET Core console application to contain single test cases.

+6
Mar 17 '17 at 18:52
source share

I had problems with VS 2017 that found my UnitTest. This was not the exact problem John asked, but it was the first google result I was looking for, so I wanted to share my problem.

I had an outdated solution coming back from VS2010, rolling VS2013, VS2015. Now in VS2017, it seems that the namespaces for the [TestMethod] attribute have been changed.

Before using

 Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0 

I created a new version of Test.dll in the project and the one used by default

 Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0 

So, I decided to create a new UnitTest project from VS2017. Perhaps changing assembly links for an old test project would work. With a new link, VS2017 managed to detect those unit tests.

+6
Jun 16 '17 at 10:45 on
source share

Make sure you are using the correct Microsoft.NET.Test.Sdk file:

 <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> 

Do not use the preview version. Or you need to switch to a console application (not a library). I have a similar problem, but with the latest version (15.0.0) it starts working again.

In addition, you may need to add:

  <ItemGroup> <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> </ItemGroup> 

but I do not think it is necessary.

+5
Apr 04 '17 at 2:18 on
source share

I know that the OP indicated this in its checklist, but it's easy to miss this point by performing a clean install of Visual Studio 2017 and creating a new project. In addition to the NUnit project template and the NUnit Framework, you must install the NUnit adapter separately, for example, using the NuGet Install-Package NUnit3TestAdapter -Version 3.9.0 . After that, the Visual Studio 2017 community began to detect unit tests without any problems.

+4
Jan 29 '18 at 14:19
source share

In my case, Test Explorer could not find my tests after I moved the project to a new solution.

The answer was simply that I had a link to the old MS test adapter in my project.

I had a duplicate of the line below for version 1.1.11 of the MS Test adapter in my cs.proj file:

<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" />

To fix the problem,

  • Right-click the project and select Upload Project.
  • Right-click on the project and select "Edit."
  • Delete the line that imports the old version of the adapter.
  • Right-click the project and select Update Project.
  • Reconstruction of the solution / project
+3
Sep 07 '17 at 7:57
source share

for me the question was I mistakenly placed testcases in the inner class

 [TestClass] internal class TestLib { } 

which led to the fact that control samples were not identified.

+3
Aug 30 '18 at 12:34
source share

It was easier for me to create a new test project that works great with Visual Studio 2017 ... and just copy the test files, add links and NuGet packages as needed.

enter image description here

+2
Aug 07 '17 at 3:28
source share

In my case, it was a project in which I updated a test project from an earlier version of .Net. in app.config, I had prefab bindings to previous versions of dependent assemblies.

After committing assembly bindings to app.config, my tests were discovered.

+2
Dec 08 '17 at 11:19 on
source share

opening

The top answers above did not work for me (reboot, upgrade to version 1.1.18 ... I was already updated by deleting temporary files, cleared NuGet cache, etc.).

I found that I had different links to MSTest.TestAdapter and MSTest.Framework in different test projects (my solution has two). One was listed in 1.1.18 as ...

packages.config

 <package id="MSTest.TestAdapter" version="1.1.18" targetFramework="net461" /> <package id="MSTest.TestFramework" version="1.1.18" targetFramework="net461" /> 

... but another has links to 1.1.11. Some of the answers above led to this discovery when two versions of the libraries appeared in my temporary directory (% TEMP% \ VisualStudioTestExplorerExtensions \) after restarting Visual Studio.

Decision

Just updating my .config package for version 1.1.18 is what restored my unit test functionality to VS. It seems that there are some errors that do not allow side-by-side links to the MSTest libraries. Hope this helps you.

More information:

  • Visual Studio 2017 Ent: 15.5.6 (I updated from 15.0.1 with the hope of fixing this problem, but I had it in both)
+2
Feb 01 '18 at 19:12
source share

It’s just that this problem, when the visual studio could not find my tests, could not see the button to run them in addition to the method, and they were not picked up by performing all the tests in the project.

It turns out my test class was not public! The publication allowed V.S. detect tests.

+2
Aug 29 '18 at 15:04
source share

In my case, it was a UWP project, present in the solution causing the problem.

When I unloaded the UWP project, tests were discovered. When I downloaded it, the test will disappear again.

Try to unload all projects and save only the test project. In Test Runner, ten recovery solutions and test scans appeared. Download projects one by one and rebuild the solution each time to find out which project is causing the problem.

sample repo

VS Error Report

+1
Mar 31 '17 at 12:52
source share

I tried everything but nothing helped. In my case, I had a solution with several test projects, and some of them used the old ms-test environment, so Visual Studio found only those.

I installed test frame packages for all test projects as shown in the accepted answer . Then they removed the links to the old quality tools, restarted Visual Studio, and now I see all the tests.

+1
Aug 18 '17 at 9:21 on
source share

I had the same problem. My solution was fine, but suddenly, when I opened the solution, I found out that the tests were gone.

Finally, I downgraded the Microsoft.VisualStudio.TestPlatform.TestFramework and Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions package to a very old version (using the NuGet manager) and testing methods. Then I upgraded to the latest version and was still there.

So just downgrade and upgrade packages.

+1
Nov 23 '17 at 7:23
source share

For C ++:

Since there are no special questions for C ++ tests, but the topic is very important, that’s what helped me when I had problems finding tests.

If you installed only Desktop Development with C ++ , then the solution should also install the Universal Development Platform using the optional C ++ Universal Windows Platform tools . You can select them in the web installer of the visual studio.

After that rebuild your test project, and test detection should work.

By the way, I created a unit testing project in VS2017. This may be important, as some users mentioned that they had problems opening in projects that were migrated from VS2015 to VS2017.

+1
Mar 03 '18 at 17:28
source share

Removing the old.dll should help. Cleaning up temporary files located in the% TEMP% directory in the C: \ Users (yourusername) \ AppData \ Local \ Temp directory

+1
Apr 04 '18 at 9:05
source share

Solution app.config my app.config file from my unit test project. Tests will appear again!

This file referred to some dll in bindingregirects that were not actually present in the project links. Re-add the assembly necessary for your project.

+1
Jun 25 '18 at 7:56
source share

In my case, none of the above helps me. But I downgrade the NUNit3TestAdapter to version 3.8.0, and then upgrade to the latest version (3.10.0)

+1
Aug 20 '18 at 9:22
source share

Problem

The problem is that Visual Studio gets "confused" over the dotnet kernel versions on the machine. When I went to the control panel -> uninstall programs, I had 8 different SDKs and Runtimes of the dotnet kernel. This somehow made VS silently have an error when trying to find tests.

Confirm Problem

You can check this problem by going to the command line and getting the dotnet version on $ dotnet --version . If you see anything other than the latest version that you installed, your machine has some inconsistency and does not use the correct version. Example ... If you have the dotnet 1.0.1 kernel installed, but when you get the version on the command line and it says 1.0.0 , this is the problem.

Decision

Remove all old stuff. I started with what I needed, although I had to remove (the oldest versions of rc dotnet), but when testing the problem, it still gave the wrong version. In the end, I agreed to do everything clean. I AM...

  • Removed all applications for visual studio (on my machine VS2015 and VS2017)
  • Removed all versions of the dotnet kernel (even the most recent ones)

After my machine was completely empty of all VS and donet, I installed only VS2017 (it comes with the latest dotnet). I created an xUnit test project, and a test researcher immediately discovered the SOLVED test

This may seem redundant, but I spent two weeks trying to fix it differently. If you have a problem, just do it, even if you need time to remove / reinstall items, it will probably save your time.

References

  • See the @epestic blog post for more information on fixing the problem.
0
Apr 01 '17 at 15:40
source share

At first I tried to use MSTest. After that I will switch to the Nunit test. Then I wanted to return MSTest. I removed all nUnit codes and links, but Test Explorer did not show the MSTest methods. Decision. I deleted all the mstest nuget links and reinstalled. Done.

0
06 Sep '17 at 13:06 on
source share

For me, changing TargetFramework in the .csproj project .csproj from

  <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> </PropertyGroup> 

to

  <PropertyGroup> <TargetFramework>net46</TargetFramework> </PropertyGroup> 

worked.

0
Sep 21 '17 at 15:49
source share

In my case, the problem was that a static library (lib) was installed for the project type, and it should be a dynamic library (dll)

0
Sep 20 '18 at 16:52
source share

Sometimes I find that if you have stackoverflow exceptions in your unit test code, visual studio will mark this block test as not running and stop running other test cases that follow this example.

In this case, you need to figure out which case is causing the stackoverflow exception.

0
Oct 18 '18 at 13:41
source share

Sometimes changing the namespace of the tests works. I had a folder structure as follows:

A |___B | |___D |___C___E

The namespace was flat, like Tests. <Name>, and they did not appear in the test window. When I changed the namespace to the directory structure, all the tests showed up. Now I can go back to any other namespace structure I want.

Do not forget to build your project!

0
Dec 20 '18 at 3:17
source share

Check if the NUnit 3 test adapter is turned on . In my case, I already installed it a long time ago, but suddenly it somehow turned off. It took me quite a while before I decided to check out this part ...

NUnit 3 Test Adapter Disabled

0
Dec 20 '18 at 10:41
source share
  • one
  • 2



All Articles