Visual Studio 2015 or 2017 does not discover unit tests
Asked Answered
S

46

171

EDIT 2016-10-19:

The original question was about an issue specific to VS2015 CTP6 with the XUnit test runner. It's clear from the answers that there is a much broader issue with unit test discovery in Visual Studio which may occur in many different situations. I have cleaned up my question to reflect that.

I have also included a script in my own answer that I still use to this day to solve similar problems when they appear.

Many other answers have also proven helpful in better understanding the intricacies of the VS test runner. I appreciate that people are still sharing their solutions!


Original question 2015-04-10:

Since yesterday, my Visual Studio Test Explorer won't discover tests for any of my projects. It does not show the green loading bar after building, either.

When I go to the Visual Studio Test Explorer and click "Run All", or when I right-click any test method and select "Run Tests", I get the following in my output window:

Could not load file or assembly 'Microsoft.VisualStudio.Web.ProjectSystem, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I am running Visual Studio 2015 CTP 6 on Windows 10 Pro Technical Preview, build 10041. The .NET Framework version does not seem to matter - it happens on 4.0, 4.5.2 and 4.6.

I tried with the following testing frameworks and all of them give the same behavior:

  • Microsoft.VisualStudio.QualityTools.UnitTestFramework v14.0.22609.0
  • xunit v2.1.0-beta1-build2945 with xunit.runner.visualstudio v2.1.0-beta1-build1051
  • NUnit v2.6.4 with NUnitTestAdapter v2.0.0

I found an issue on GitHub (xunit) that appeared to be similar: Cannot get tests discovered #295, with this comment from the xunit team:

Be aware that Visual Studio 2015 CTP 5 has been reported to be broken by many people with unit testing in general (not just xUnit.net), so don't expect that to work.

Also, please make sure you've cleaned out Visual Studio's runner cache. If it gets corrupted, Visual Studio will permanently misbehave until it's deleted. To clear the cache, shut down all instances of Visual Studio, then delete the folder %TEMP%\VisualStudioTestExplorerExtensions (honestly, it probably wouldn't hurt to delete everything in %TEMP% that can be deleted).

I tried their suggestion to delete the folder %TEMP%\VisualStudioTestExplorerExtensions. Unfortunately that did not fix the problem.

I noticed that ReSharper actually is able to discover some tests. It only works for the VS and NUnit tests, not for xunit.

There has to be some sort of temp or cache folder I need to clear, but I know Visual Studio has many of them and not all of them can be deleted without unwanted side-effects.

Salvage answered 10/4, 2015 at 11:14 Comment(7)
I'm so glad I stumbled upon this, it reminds me of why I'm using a 3rd party test runner (in my case ncrunch). I gave up on mstest a long time ago for similar reasons. Of course, that's no solution if you're stuck with mstest...Unbacked
related: #35104281Cerise
with VS 2017, incredibly enough, a cleaning of my temp and localappdata VS2017 related folders, a close + reload + clean solution and a Windows reboot didn't help. However, surprisingly, a simlpe "unload - reload" project on only one of my test projects did help the test discovery stopping hanging. I don't use 3rd party unit test package.Carvajal
For some ppl this might be interesting or more relevant (I do not think I should add it as an answer) : No Source Available in Test Explorer - github.com/Microsoft/testfx/issues/274Coalition
This could be a fix for someone https://mcmap.net/q/121300/-how-to-fix-this-c-issue-no-test-matches-the-given-testcase-filter-fullyqualifiednameCrazed
Does this answer your question? Why is the Visual Studio 2015/2017/2019 Test Runner not discovering my xUnit v2 testsLuxuriance
Related post - Unit Tests not discovered in Visual Studio 2017Gloat
S
36

EDIT 2016-10-19 (PowerShell script)

This issue still returns every now and then. I wrote a small PowerShell snippet to automate clearing the relevant cache/temp folder/files for me. I'm sharing it here for future readers:

@(
"$env:TEMP"
"$env:LOCALAPPDATA\Microsoft\UnitTest"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\1033\ProjectTemplateMRU.xml"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\ComponentModelCache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\Designer\ShadowCache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\ImageLibrary\cache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio Services\6.0\Cache"
"$env:LOCALAPPDATA\Microsoft\WebsiteCache"
"$env:LOCALAPPDATA\NuGet\Cache"
) |% { Remove-Item -Path $_ -Recurse -Force }

Make sure to close Visual Studio beforehand and it's probably a good idea to reboot afterwards.

Deleting the TEMP folder may not be necessary and may in some cases even be undesirable, so I would recommend trying without clearing the TEMP folder first. Just omit the "$env:TEMP".

Original answer 2015-04-12

The problem was "solved" after a thorough cleaning of Visual Studio-related temp/cache folders.

Since I did not have the time to go through everything one-by-one and then test in-between, I unfortunately don't know which one actually caused the problem.

These are the exact steps I've taken:

  1. Closed Visual Studio
  2. Used CCleaner to clear system and browser temp files/folders
  3. Manually cleared/deleted the following files/folders:

    • %USERPROFILE%\AppData\Local\assembly
    • %USERPROFILE%\AppData\Local\Microsoft\UnitTest
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\1033\ProjectTemplateMRU.xml
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\Designer\ShadowCache
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ImageLibrary\cache
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio Services\6.0\Cache
    • %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
    • %USERPROFILE%\AppData\Local\NuGet\Cache
    • %USERPROFILE%\AppData\Local\Temp
Salvage answered 12/4, 2015 at 12:41 Comment(8)
Thanks, worked for me after clearing the Microsoft\VisualStudio\14.0\ and Microsoft\VisualStudio Services\6.0\Cache folders you describe.Ruphina
Surely you mean \Microsoft\VisualStudio\14.0\ImageLibrary\ImageLibrary.cache?Daliadalila
I have removed everything from %TEMP% and it does not work, but when I readd 'VisualStudioTestExplorerExtensions' directory (empty) everywhing works perfectly :-) (There is anserw with that solution on the bottom at current day)Descendent
I want to confirm that this solution works for me with VS2015 Update 3 and Resharper 10. But you need to restart to see the miracleCasillas
I deleted only one file \AppData\Local\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml it heplsRepairer
I've come across this multiple times where VS decides it cannot find/execute the unit tests... something like "No tests found to run." is reported in the output window. Simply restarting VS is all that is required.Placative
This worked for me as well..power of reusable code.. appreciate the answer and the efforts of this answerer..Bash
After trying several things, this is the only one that worked for me. I had only problems with x64 solutions.Heptarchy
H
158

To my surprise, clearing temp files located in the %TEMP% directory resolved the issue for me.

Note: This path is generally at C:\Users\(yourusername)\AppData\Local\Temp

As @Warren-P included, you can navigate to the temp folder by putting in %temp% in Start Menu, or launch "File Explorer" and enter %temp% in the address bar.

Hollow answered 22/6, 2015 at 23:20 Comment(13)
Or you just type in %TEMP% in the Start Run menu and it finds your temp folder for you without you guessing what the value of temp is.Scorpaenoid
I wouldn't advice anyone to delete all contents from this folder without any criteria. Applications rely on this folder to store important data. You may start having problems with many applications and may need to reinstall them in order to make it work properly again.Quartziferous
@ZéCarlos Any application that stores important data in the %TEMP% directory deserves to stop working.Laporte
This worked for me too. Thanks man, you saved me from lot of embarrassment.Doughman
not an embarrassment for you, it's an utter failure from Microsoft that you have to take such ridiculous steps to keep a 1000+ USD IDE running.Hom
@CreeTar agreed. Shame on MicrosoftZurkow
Worked for me in VS2017 as well!Diplosis
How did you found out, that clearing the temp folder will eliminate this issue :D weird. Thanks a lot! - VS2017Fate
This should be higher up on the page.Rhinoceros
You fixed my VS2017 too!Blaney
If you're concerned about clearing the whole temp directory, only clearing the Temp\VisualStudioTestExplorerExtensions sub-directory seems to fix the problem.Narration
In my case, i was opening the project from NAS and 'Developer Command Prompt 2015' for some reason could not navigate and read the test. In contrast the Visual Studio was able to build and proceed with application normally.Objectivity
As incredulous as I was, this also fixed an issue for me where a solution with many projects was only loading some of the unit tests.Dortch
E
92

It could be that your code is compiled with x64 therefore have to enable the Default Processor Architecture as X64.

Test > Test Settings > Default Processor Architecture > X64
Estray answered 5/12, 2015 at 17:20 Comment(3)
This has bitten me a few times. Even after all these years I still can't think of a good reason why by default the test settings are not selected to automatically match the project's current build configuration. Just seems like pointless duplicate configuration to me.Dopey
Windows update and / or VS update changes the default architecture without telling you.... aaarghBenevolent
And 4 years later, this is still helpful. ThanksFloatfeed
M
69
  • Check out, if NUnit Test Adapter 2/3 is installed in VisualStudio.
    (Tools>Extensions and Updates )

  • Make sure that correct processor architecture is chosen:
    (Test>Test Settings>Default Processor Architecture)

Monique answered 27/1, 2016 at 16:53 Comment(5)
This is what finally worked for me. After trying everything else.Veinule
Makes you feel like a fool digging around in temp folders first when the extension is not even installed. Thanks for posting this.Holusbolus
Also check if you use the correct extension. There is a separate one for NUnit 2.x and NUnit 3.x.Totalizer
When you're targetting .NET Standard, you actually need to install the NuGet package NUnit Test Adapter instead of a VSIX extension. github.com/nunit/docs/wiki/.NET-Core-and-.NET-StandardKoren
Try to get NUnit3TestAdapter from nuget, instead of VSIX. That's the better approachClambake
S
36

EDIT 2016-10-19 (PowerShell script)

This issue still returns every now and then. I wrote a small PowerShell snippet to automate clearing the relevant cache/temp folder/files for me. I'm sharing it here for future readers:

@(
"$env:TEMP"
"$env:LOCALAPPDATA\Microsoft\UnitTest"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\1033\ProjectTemplateMRU.xml"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\ComponentModelCache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\Designer\ShadowCache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\ImageLibrary\cache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio Services\6.0\Cache"
"$env:LOCALAPPDATA\Microsoft\WebsiteCache"
"$env:LOCALAPPDATA\NuGet\Cache"
) |% { Remove-Item -Path $_ -Recurse -Force }

Make sure to close Visual Studio beforehand and it's probably a good idea to reboot afterwards.

Deleting the TEMP folder may not be necessary and may in some cases even be undesirable, so I would recommend trying without clearing the TEMP folder first. Just omit the "$env:TEMP".

Original answer 2015-04-12

The problem was "solved" after a thorough cleaning of Visual Studio-related temp/cache folders.

Since I did not have the time to go through everything one-by-one and then test in-between, I unfortunately don't know which one actually caused the problem.

These are the exact steps I've taken:

  1. Closed Visual Studio
  2. Used CCleaner to clear system and browser temp files/folders
  3. Manually cleared/deleted the following files/folders:

    • %USERPROFILE%\AppData\Local\assembly
    • %USERPROFILE%\AppData\Local\Microsoft\UnitTest
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\1033\ProjectTemplateMRU.xml
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\Designer\ShadowCache
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ImageLibrary\cache
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio Services\6.0\Cache
    • %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
    • %USERPROFILE%\AppData\Local\NuGet\Cache
    • %USERPROFILE%\AppData\Local\Temp
Salvage answered 12/4, 2015 at 12:41 Comment(8)
Thanks, worked for me after clearing the Microsoft\VisualStudio\14.0\ and Microsoft\VisualStudio Services\6.0\Cache folders you describe.Ruphina
Surely you mean \Microsoft\VisualStudio\14.0\ImageLibrary\ImageLibrary.cache?Daliadalila
I have removed everything from %TEMP% and it does not work, but when I readd 'VisualStudioTestExplorerExtensions' directory (empty) everywhing works perfectly :-) (There is anserw with that solution on the bottom at current day)Descendent
I want to confirm that this solution works for me with VS2015 Update 3 and Resharper 10. But you need to restart to see the miracleCasillas
I deleted only one file \AppData\Local\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml it heplsRepairer
I've come across this multiple times where VS decides it cannot find/execute the unit tests... something like "No tests found to run." is reported in the output window. Simply restarting VS is all that is required.Placative
This worked for me as well..power of reusable code.. appreciate the answer and the efforts of this answerer..Bash
After trying several things, this is the only one that worked for me. I had only problems with x64 solutions.Heptarchy
G
22

One reason for this problem is that your test class is not public. MSTest only discovers tests from public classes.

Greenbelt answered 11/3, 2017 at 2:20 Comment(2)
While this is not 100% correct and I had an non-public class working fine, at some point its unit test stopped working. When I changed the unit test class to public, it started working again. Go figure!Bresnahan
This solved it for me. By default Visual Studio adds test classes without the public keyword, and it wouldn't see them until I made them public.Algonquian
H
15

In Visual Studio 2015(Update 3) if you want to attach the tests in the test explorer then have to install the NUnit Test Adapter.Download the adapter from Tools->Extension And Updates->Online tab(you have to search for the adapter)->Download. By restarting the Visual Studio you can see the change for the test framework.

Humo answered 8/2, 2017 at 9:59 Comment(4)
Following your instructions, I searched for "nunit" and found "NUnit 3 Test Adapter" which, after "Download" (install), resolved my issue. Searching internet for this issue finds other SO article at linkLegroom
This is better than Nuget package manager in some scenarios as it does not change the config filesBodwell
@Bodwell but when you're targetting .NET Core or Standard, you actually need the NuGet package, check my answer down below: https://mcmap.net/q/119921/-visual-studio-2015-or-2017-does-not-discover-unit-testsKoren
You save my life ! Thanks, I tried so many solutions and it didn't works. Mine was google test adapter.Bambino
H
9

I don't have a complete answer to this, but I have determined some things by playing with a test project:

  1. The xunit.runner.aspnet : 2.0.0-aspnet-beta4 that appears to be part of the official beta4 aspnet5 release does not work in Visual Studio.
  2. Instead, using "xunit": "2.1.0-*" and "xunit-runner.dnx": "2.1.0-*" packages DO work in Visual Studio.
  3. In order for VS to discover the tests, your project MUST have a SINGLE command named "test" that runs "xunit.runner.dnx". Adding additional commands may break it.
  4. If your Test Explorer window still ends up empty, REMOVE the "test" command from your project, then re-build the solution, then add the "test" command back to the project.json.
  5. Clearing all your caches as per @Fred-Kleuver 's suggestion may help, but I haven't done all the steps in isolation, so I'm not sure.

This is current as per VS 2015 CTP 6, using the beta4 releases, not the dailies.

Hawes answered 14/5, 2015 at 21:50 Comment(4)
Okay, I've confirmed (by having a co-worker try it) that the above fix does not require any clearing of the caches or temp files.Hawes
Above says "Instead, using "xunit": "2.1.0-" and "xunit-runner.dnx": "2.1.0-" packages DO work in Visual Studio.". This works, thanks!Fulgurous
Btw, as a followup, everything just seems to work fine now in VS 2015 as of the current releases. No fussing required to get new tests to show up or anything.Hawes
Finally, there is now a proper guide from MS on exactly which versions of xunit to use with which versions of DNX, here: xunit.github.io/docs/getting-started-dnx.htmlHawes
T
9

I had an instance where some tests would not be picked up because I had made them async like the following:

public async void This_IsMy_UnitTest()

The problem was I forgot to make them return a Task and not void when I did the switch-over. One would think this would cause an error or failed test but nope. The unit tests in that class were fully ignored and acted like they didn't exist.

It wasn't after about 3 clean and builds + restarting VS.NET that I saw the test run and fail indicating I forgot to add the Task return type:

public async Task This_IsMy_UnitTest()

After the update, the unit tests were found and worked correctly. This might be an edge case, but having async tests for using await within but not having the signature correct can cause this same issue and it's not the 1st time I've done this.

Thermos answered 4/11, 2016 at 19:21 Comment(1)
Solved the issue for me!Crack
S
8

Go to Nuget package manager and download Nunit Adapter as follow.

enter image description here

Smuggle answered 28/12, 2016 at 15:22 Comment(2)
Thank you, in my case I had NUnitTestAdapter instead of NUnit3TestAdapter. That solved my problem.Headphone
Adding the NUnit3TestAdapter nuget package to a solution or to a project wouldn't fix the problem for all other solutions in general, but only for those to which it has been added. In order to do it generally for all solutions/projs, add the NUnit 3 Test Adapter extension to your visual studio as explained at https://mcmap.net/q/119921/-visual-studio-2015-or-2017-does-not-discover-unit-testsYonit
T
6

I had the same pronlem but the folder "%TEMP%\VisualStudioTestExplorerExtensions" did not exist on my machine so as i read the posts i had the idea to create it and it works. The test explorer is now able to show all my tests. Thanks.

Tadio answered 7/3, 2016 at 11:1 Comment(0)
L
6

Just restart Visual Studio and in Test Explorer do "Run All" ... All my tests are discovered then.

Lincoln answered 23/2, 2017 at 11:18 Comment(1)
I've noticed also just closing Test Explorer and reopening it and choosing Run All works too. I'm not sure yet if it always works but it worked this time.Morganne
C
5

In my case (Visual Studio Enterprise 2015 14.0.25425.01 Update 3, Resharper 2016.2) I just needed to do a clean solution from the Build menu. Rebuilding the solution then cause the test explorer to "wake up" and find all the tests again.

Cirillo answered 11/9, 2016 at 6:7 Comment(0)
Y
5

The solution in my case was just to install the NUnit 3 Test Adapter extension to my Visual Studio 2015.

'Extensions and Updates' is present under 'Tools' meue

Yonit answered 18/8, 2017 at 4:55 Comment(2)
How does your answer add value to the question? Have you read them? There are already two answers that recommend the exact same solution: https://mcmap.net/q/119921/-visual-studio-2015-or-2017-does-not-discover-unit-tests , https://mcmap.net/q/119921/-visual-studio-2015-or-2017-does-not-discover-unit-testsFiorenze
Well, I read the first one (i.e. https://mcmap.net/q/119921/-visual-studio-2015-or-2017-does-not-discover-unit-tests) but that is different to my answer as that is suggesting to add NUnit Adapter nuget package to a solution or to a project, which wouldn't fix the problem for all other solutions in general. With regards to the second one, I've to admit I missed to see it. Perhaps adding a screenshot helps the eye catch it when there are two many answers present to a questionYonit
L
4

In my case, the problem was "between the chair and keyboard". I had switched to a configuration in the Configuration Manager which did not include my unit test projects on build. Switching back to a configuration (e.g. Debug) which includes all projects fixed the issue.

Lampley answered 3/9, 2015 at 19:56 Comment(0)
I
4

In my case, MSTest under VS 2015 was ignoring tests with test (i.e. method) names that were longer than 174 characters. Shortening the name allowed the test to be visible. This was determined via guess-and-check by manipulating the test name.

Iolanthe answered 4/10, 2016 at 20:38 Comment(0)
A
4

This probably won't help most people, but someone inexperienced at unit testing had written a test method that returned bool instead of void:

[TestMethod]
public bool TestSomething()

Changing the return type to void fixed the problem.

Adventitious answered 30/11, 2016 at 4:12 Comment(1)
Still interesting to know that returning a type prevents test discovery, I didn't know that.Salvage
E
3

Ensure you have xunit.runner.visualstudio package in your test project packages.config and also that was correctly restored.

I know this was not the case of the original question however it could save time for someone like me.

Echeverria answered 9/3, 2017 at 15:59 Comment(0)
T
3

I would just like to add that I found an entirely different solution to the ones above.

I had declared my test class as below:

[TestClass]
class ClassificationTests
{
   //unit tests
}

As soon as I added the public modifier to the class, it worked as expected!

Tiffa answered 10/5, 2017 at 17:55 Comment(0)
A
2

This topic is somewhat outdated, but my solution to the missing Test status in VS2015:

The task-status only shows up on the Debug buildconfiguration. Ofcourse this also makes it impossible to debug your test through the test-explorer.

Alack answered 1/2, 2017 at 20:53 Comment(0)
S
2

Somehow my project was set to compile as a Static Library (.lib). After changing this to a Dynamic Library (.dll), tests where discovered correctly by Visual Studio 2012.

My Unit Test Project ->
Properties ->
Configuration Properties ->
General ->
Configuration Type
Strapping answered 5/9, 2017 at 17:39 Comment(1)
This is my problem as well. However, I want to use a lib and want to know how to make it work.Neutretto
K
2

If you're targetting .NET Standard or .NET Core, you need to use the NuGet package for NUnit Test Adapter and not the extension.

It is recommended to install the adapter from NuGet if you are testing .NET Core or .NET Standard projects. The VSIX adapter does not, and will not, support .NET Core because VSIX packages cannot target multiple platforms.

Source: NUnit GitHub Wiki

.

Also check the FAQ there:

My tests aren't showing up in Visual Studio 2017?

  • Are you using the NuGet package?
  • Are you using version 3.8.0 or newer of the NuGet package?
  • Do your tests target .NET Core or the full .NET Framework? (see above)
  • Have you added a Package Reference to Microsoft.NET.Test.Sdk?
  • Have you restarted Visual Studio? It is still a bit tempermental.

Source: NUnit GitHub Wiki

Koren answered 23/11, 2017 at 16:50 Comment(0)
M
2

This happened to me because my test project contained an app.config. It was automatically added by NuGet packages for assembly redirection, but my tests seemed to run fine without it.

See: https://developercommunity.visualstudio.com/comments/42858/view.html.

Microphone answered 26/11, 2017 at 15:20 Comment(0)
I
1

I had the same problem. I just cleaned and rebuilt the project and I was able to see the tests that were missing.

Immortalize answered 22/8, 2016 at 19:43 Comment(0)
S
1

Popping in to share my solution. I was on Windows 10, Visual Studio 2015, NUnit 3.5, NUnit Test Adapter 3.6 (via NuGet, not the VISX extension) and none of my tests were being discovered. My problem was that in the Tests project of my solution, somehow a shortcut to my "Documents" folder had been created within the project folder. I'm guessing the test adapter was seeing the shortcut and getting hung up trying to figure out what to do with it, resulting in the failure to display unit tests.

Strawberry answered 15/12, 2016 at 19:57 Comment(0)
R
1

Deleting the file \AppData\Local\Microsoft\VisualStudio\14.0\1033\SpecificFold‌​erCache.xml solved the issue for me.

Relevance answered 27/12, 2016 at 11:13 Comment(0)
J
1

I was also bitten by this wonderful little feature and nothing described here worked for me. It wasn't until I double-checked the build output and noticed that the pertinent projects weren't being built. A visit to configuration manager confirmed my suspicions.

Visual Studio 2015 had happily allowed me to add new projects but decided that it wasn't worth building them. Once I added the projects to the build it started playing nicely.

Jounce answered 28/2, 2017 at 16:28 Comment(0)
P
1

I resolved it by changing X64 to : Right click on project -> Properties -> Build -> Platform target -> Any CPU

Prescind answered 27/4, 2017 at 4:23 Comment(0)
U
1

It was so easy for me to fix the issue as:

  • Select your Unit Test Project
  • Click on 'Show All Files' button in the Solution Explorer and new temporary files appeared in the file tree of the Solution Explorer within 'obj\x86\Debug'.
  • Delete these temporary files and rebuild project.
  • Retried to run tests and worked!.
Ulda answered 26/1, 2018 at 12:14 Comment(0)
L
1

We had the same problem. We have a big VS 2015 solution with multiple C# projects in it and even more test projects.

Resharper's test discovery worked just fine, but VS Test Explorer failed miserably.

Turns out that the projects didn't have the same version of MsTest TestFramework and TestAdapter, and that sometimes they used NuGets and other times good old references, and that is not supported apparently (so much for such an expensive IDE).

Removing all Microsoft.VisualStudio.Test* references and then adding / updating the two MSTest NuGets fixed the problem.

Lailalain answered 15/8, 2018 at 16:16 Comment(0)
P
1

I solved this problem by realizing that the Target Framework for my test project was different than the project under test. Yes, I caused this problem by changing the target framework from the default (Project>Properties>Application), but failed to this this for the test project, which was created several weeks later. The mismatch did not cause a compiler error, but it did result in a warning in the Error List window. Once I selected the option to display warnings, the solution was obvious.

Pozzy answered 13/11, 2018 at 22:32 Comment(0)
M
1
  1. Update nunit.framework to latest version.
  2. Download nunit test adapter from nuget
  3. Restart Visual studio
Mcduffie answered 2/3, 2020 at 9:22 Comment(1)
This one worked for me, just make sure to install the latest nunit test adapter.Profluent
V
0

I was struggling with same problem for VSTest framework and my native unit tests.

So, after doing all those things you mentioned before, I removed every occurence of '#' symbol in my solution's directory path. It actually works.

I'm leaving it here for googlers who will find this question in future.

Valverde answered 29/10, 2016 at 12:38 Comment(0)
A
0

Make sure your class with the [TestClass] attribute is public and not private.

Alicaalicante answered 18/2, 2017 at 19:53 Comment(0)
R
0

I made the mistake of creating async methods but returning void.

Changed: public async void Test()

To: public async Task Test()

Ruffian answered 10/3, 2017 at 17:0 Comment(0)
U
0

Make sure your Test Methods do not have parameters. This is another way your test will not show up.

No Errors or Warnings.

Unarm answered 13/3, 2017 at 19:14 Comment(1)
This is most certainly not true since MSTest v2Impinge
S
0

I would like to add one further reason tests may not be found, in my case it pertained C++ unit tests that were not found.

In my case tests were not found for a particular project because its output directory was not contained within the project directory, changing this ensured the tests were found.

Singly answered 12/4, 2017 at 8:5 Comment(0)
U
0

If you are working with multiple App or Web.Config files. eg:

enter image description here

Its likely you are using a Config that is RELEASE MODE and that will strip the Debug mode setting from the config:

  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

Change the Config to one that doesn't remove DEBUG MODE.

Unchristian answered 5/6, 2017 at 1:55 Comment(0)
S
0

I had the same issue. The unit test template of Visual Studio 2015 (Update 3) generates a class with TestContext property defined as follow:

    private TestContext testContextInstance;

    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    public TestContext TestContext
    {
        get
        {
            return testContextInstance;
        }
        set
        {
            testContextInstance = value;
        }
    }

After changing it to a public field (ungly) the test runner could discover the test.

public TestContext TestContext;

Very strange behaviour, but it was the cause of the issue in my case.

Sugarcoat answered 6/6, 2017 at 12:39 Comment(0)
L
0

After spending 2 days... none of the above worked for me. The only "solution" was: Go to project properties -> Build Tab. Then click Advanced button on the right bottom corner of the pane. Change "Debug Info:" to "full" and click OK.

Here are the screen shots: enter image description here

enter image description hereenter image description here

Lauree answered 18/6, 2017 at 20:35 Comment(0)
C
0

Disable Windows Defender Service. Turning this off immediately caused all of my unit tests to show up in Test Explorer.

Chau answered 26/6, 2017 at 18:11 Comment(0)
P
0

In the VS Output pane (switched to the Test view), there was this error:

Could not load file or assembly 'XXX.UnitTest, Version=9.4.0.0, Culture=neutral, PublicKeyToken=14345dd3754e3918' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)

In the project settings for the test project, under the Signing tab, someone had checked 'Sign the assembly'. Unchecking that and building caused the tests to show up.

A colleague also solved the same issue by adding keys from this post to the registry:

https://blogs.msdn.microsoft.com/keithmg/2012/03/20/strong-name-validation-failed-exception-from-hresult-0x8013141a/

Poul answered 2/8, 2017 at 16:28 Comment(0)
P
0

The only thing that worked for me was: Remove C:\Users(yourusername)\AppData\Local\Temp

Other suggestions typically are valid. But for some reason, if VS does not pick up your changes and keeps barking in your output it cant discover tests, cleaning this dir can do the trick. And, yes, it may be just "some day" you startup and none of your solutions will work anymore, wheras "yesterday" everything worked fine.

Posterity answered 27/4, 2018 at 8:0 Comment(1)
Yes, there are already two answers on the front page from 3 years ago suggesting just that. One is the accepted answer, the other is the most-upvoted answer.Salvage
F
0

For me the solution was cleaning and rebuilding the Test Project

Build > Clean

Build > Build

I haven't read that in the answers above, that's why I add it :)

Fjeld answered 3/6, 2020 at 15:30 Comment(0)
S
0

I believe you already found the issue, but in my case helped to simply install the Microsoft.NET.Test.Sdk. Make sure you add it to your test project. I've spent few days trying to solve the problem and it's as simple as that.

Microsoft.Net.Test.Sdk should be installed no matter what testing framework you are using.

https://i.stack.imgur.com/Roof5.png

Sedgewick answered 22/2, 2021 at 13:28 Comment(0)
E
0

Please note that I have walkthrough over the current answers and did not find related to loading/unloading the test projects (the trick which worked in my case and I have already answered it on another similar question on SO here https://mcmap.net/q/121302/-visual-studio-test-explorer-window-not-refreshing).

Here we go:

I was also facing the same issue, as a workaround I Unloaded my test project and then Reloaded back; then ran the test again. This time it refreshed the Test explorer :)

My VS version: VS Professional 2019 Version 16.9.6.

Note: I had to do this to all my Test projects.

Ethbin answered 23/6, 2021 at 15:20 Comment(0)
P
-1

For me upgrading to version 3.7 of NUnit worked.

Piane answered 28/6, 2017 at 2:17 Comment(1)
version 3.7 of what ?Poul

© 2022 - 2024 — McMap. All rights reserved.