Tests not running in Test Explorer
Solution 1
If your projects aren't all AnyCpu then you may also want to check that the following 2 settings match:
[Right click test project] -> properties -> Build -> Platform target - e.g. x64
[Main Menu] -> Test -> Test Settings -> Default Processor Architecture -> X64
I found that when these didn't match my test project would silently fail to run.
Solution 2
I had to change my async test methods to return Task instead of void.
The tests were then active and runnable in Test Explorer.
Solution 3
If you are using NUnit rather than MSTest then you will need either the NUnit 2 Test Adapter or NUnit 3 Test Adapter for Visual Studio ≥ 2012/2013.
Solution 4
I had the same problem in VS 2017. In my case it solved by restarting VS.
Solution 5
TLDR: Update the testing packages, look into the output -> test console
I struggled with this for a day and a half. so here's what I did to solve it:
Symptoms
- 5 Unit test projects, all discoverable in TestExplorer
- 2 out of 5 executed properly
- 3 stating not run at all
- The problem started after a .net framework update
Investigation
Since all the packages were updated during the .net framework update, I started with the differences between the working and not working projects. The first clue was that all 3 projects were using: MSTest.TestAdapter and MSTest.TestFramework
Naturally I went to the -> Output console -> Test dropdown in VS 2019 and looked at the output. Nothing useful there.
Step one of the solution: Update the MSTest.TestAdapter and MSTest.TestFramework to version 2.0.0
Step two of the solution: Now the Output console -> Test dropdown output started showing one after the other, missing packages and wrong binding redirects
Step three of the solution: Manually add the missing packages. For me those were
- System.Runtime.Extentions
- System.Reflection
- Maybe some more that I'm missing
Step 4 of the solution: Removed/Fixed the unnecessary binding redirects.
I hope this will help someone else.
Related videos on Youtube
ElGauchooo
Updated on April 08, 2022Comments
-
ElGauchooo about 2 years
I am currently working on a solution that has currently 32 Unittests. I have been working with the resharper test runner - which works fine. All tests are running, all tests are showing the right test outcome.
However, the tests are not running when using the Visual Studio test explorer.
The Test Explorer is showing all unit tests, but once clicking on "Run All", all tests are getting greyed out and show no result of the test run:
- All test classes are public
- All test classes are having the
[TestClass]
attribute declared - All test methods are using the
[TestMethod]
attribute - Both the productivity code and the test projects are targeting .NET 3.5.
- I have already tried to clean build my solution, and / or delete all
obj
,bin
,Debug
andRelease
folders
I'd appreciate any hints which would explain this behaviour.
-
kmhigashioka over 9 yearsUpdate your ReSharper. Refer to this stackoverflow.com/questions/16011775/…
-
Bernhard Hofmann over 4 yearsWouldn't it be wonderful if VS said why a test was not run? Mismatched target platform, missing test adapter, ... :(
-
Alex 75 over 4 yearsWhere is it mentioned they use ReSharper ?
-
JLRishe about 4 years@BernhardHofmann I encountered an issue just like this right now and it turns out that VS was spitting out some error messages in Output > Tests. Important. Frustrating that VS doesn't make them more visible, but that's a place to look in a situation like this.
-
Kyle Delaney about 4 yearsYou all might be interested in upvoting this feature request: developercommunity.visualstudio.com/idea/947742/…
-
hk1ll3r almost 4 yearsYear is 2020, 5 years since this questions, and still after trying 10 different answers, I couldn't get the nunit tests to run. Creating a console project to run the test code. sigh
-
Werner Bisschoff almost 4 yearsSo, very simple solution, as none of the answers actually helped... I had an syntax issue in by App.Config file for the test project.... Instead of <?xml version="1.0" encoding="utf-8"?> i had ?xml version="1.0" encoding="utf-8"?>
-
Ken Lyon about 3 years@BernhardHofmann Great reminder about Output > Tests. It'd definitely be so much easier if these details were surfaced by the "Not Run" message. i.e. "Not run because..." In my case, I had changed a TestMethod to async but not changed the return type from void to Task. I don't write these often enough to remember! Simple fix when you can find the error message!
-
profimedica over 2 years@hk1ll3r, can you share that project bit that does not run?
-
Stefan Varga over 2 yearsI had this error in Output -> Test... "Multiple versions of same extension found. Selecting the highest version. Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter ..." So I had to update MSTest.TestAdapter and MSTest.TestFramework
-
Steve Rakebrandt over 7 yearsUninstall Resharper?! I don't think that this is a solution^^
-
lukkea almost 6 yearsmy previous comment for why I gave this downvote was deleted, so I'll be a little clearer. This isn't a solution for the problem; it's a very temporary fix that doesn't solve the underlying issue. I don't think SO should be a place people should be coming to be told "turn it off and on again", that is knowledge to be learned way before you get here. Please see Joseph Simpson answer for a solution.
-
Sascha over 5 years@lukkea I followd Joseph Simpson's answer and confirmed, that all my projects where AnyCpu. I still had the problem described here. For me simply restarting VS helped. That is not the first time VS2012 has these kind of hickups (and not only on my machine). I agree with you, that this isn't a good solution, but if there is nothing wrong with the project, that might be the only help. One should check if cleaning an rebuilding doesn't help either, though.
-
Westerlund.io over 5 yearsThis helped me figure that that i needed to install the "NUnit 3 Test Adapter": marketplace.visualstudio.com/…
-
Marcel Studer almost 5 yearsthis one fixed my issues (switching from mixed platforms to anycpu)
-
user2033412 almost 5 yearsmake sure your testprojects are not netstandard2.0 but netcoreapp2.2
-
Palle Due almost 5 yearsIn my case it's the exact opposite: Any unit test project, that has the MSTest nuget packages will not run, where as the others do. Strange.
-
Palle Due almost 5 yearsSolved: I have a .testsettings file. MSTest packages require a .runsettings file. That's why the tests aren't running.
-
anon almost 5 yearsWorked. I really with VS would, you know, give us a clear warning or error message or something.
-
Halvard over 4 years+1 I tried to debug a specific test. When I finally ran another, simpler test, then I could debug the specific test. This answer got me to try that.
-
JamesHoux over 4 yearsTemporarily changing the values and changing them back to Any CPU followed by hitting Save fixed it for me. Using VS 2019 Community Edition, in a project that was originally created in VS 2017.
-
maylon over 4 yearsIn VS 2019 worked for me to install the adapter from the package manager nuget.org/packages/NUnit3TestAdapter
-
Ketobomb over 4 yearsThere is no way to wait for an async void method to finish. Async void is "fire and forget". That's why they cannot be tested.
-
Numan over 4 yearsYou saved me that day and a half! I upgraded a 4.5 FW version project and tried removing all unnecessary stuff from packages and ended up in this situation. Thanks!
-
Donald.Record over 4 yearsThis was the fix for me, along with restarting VS and deleting the .vs folder. Thank you.
-
J_L over 4 yearsThis solved my issue with a .NET Core 3.1 project that refused to execute tests in Test Explorer. Nothing else would fix it but this.
-
Éric Bergeron over 4 yearsAfter switching from .NET Framework 4.6.2 to .NET Framework 4.7.2 my tests weren't running anymore. After hours of trying, only this solution worked for me.
-
StackOverthrow over 4 yearsVS2019 version: Main Menu -> Test -> Processor Architecture for AnyCPU Projects -> X64.
-
Eru over 4 yearsthis fixed my issue as well! :)
-
BlueRaja - Danny Pflughoeft over 4 yearsAccording to this page you also need to install
Microsoft.NET.Test.Sdk
from Nuget -
Richard Garside over 4 yearsIf only 'turning it on and off again' would fix all my problems. Still surprising how many it does fix. It's slightly embarrassing that I had to go to stackoverflow to be reminded to do it, but I found this answer useful.
-
Bob Lokerse about 4 yearsIn VS 2017 I installed the Extension Nunit 3 Test Adapter and it worked.
-
Bob Lokerse about 4 yearsIn VS 2019 I also installed the Extension Nunit 3 Test Adapter and it worked. One note: I also needed to update Visual Studio.
-
Samiron about 4 yearsI wish I could give you a bunch of likes. Thanks a lot.
-
Adam Cox about 4 yearsNote to self: My original MSTest proj ref'd
Microsoft.VisualStudio.QualityTools.UnitTestFramework
(unsure which version). Resolved issues where method not run (or found) by removing that ref, and installing the latest (v2.1.0) MSTest.TestAdapter (and Framework) -
jr-juxtaposition about 4 yearsThis answer helped me find a similar cause. In my case some test projects had references to Microsoft.VisualStudio.TestPlatform.TestFramework (and did not run) while others had references to Microsoft.VisualStudio.QualaityTools.UnitTestFramework (which were the projects that would run).
-
ebyrob about 4 years@AdamCox Is
Microsoft.VisualStudio.TestTools.UnitTesting
deprecated? I had some tests using this that suddenly quit running as above after re-adding some references to a project they depended on. -
JSON about 4 years@lukka sometimes visual studio is the underlying problem and restarting is the solution
-
benmccallum about 4 years@ebyrob, Athanasios' answer below might be relevant. Seems he not only had to upgrade/upgrade to the MSTest.* packages, but also add some dependencies and fix up some binding redirects. Check your warnings output.
-
ebyrob about 4 yearsI think I was experiencing something similar. Eventually I just re-created the project from scratch. Apparently there is a line in the *.csproj file that sets
ToolsVersion
and bumping mine messed everything up. All I can say is "buyer beware" for MS unit testing and be ready to replace your *.csproj files at a moment's notice this stuff is tightly integrated and very version dependent. -
Nele Kosog about 4 years+1 Thank you! Even with the latest version of VS 2019 16.5.5 I got no message at all that indicated what was wrong. It silently failed.
-
Stephan Møller about 4 years"Clean the project, close Visual Studio, delete the TestResults folder, then restart VS, then rebuild the project. (This alone might fix your problem, but for me didn't suffice until a deleted the old test class.)" - Fixed it for me :)
-
JP Chapleau almost 4 yearsThe facepalming I did when I read this echoed over the land... Thanks for pointing out my stupidity. That worked for me. Upvoted
-
pat8719 almost 4 yearsAlthough filed under the "no duh" category. I wish this could get up-voted more as its super obvious that your return type must be Task but easy to forget (because seemingly no other unit test in the world returns anything but void) and sends you down the rabbit hole of fixing your unit test configuration when there is no actual configuration problem. Really wish this just caused a compiler or the very least throws a runtime error.
-
benmccallum almost 4 years@pat8719, sounds like a good idea for a code analyzer. They're not too hard to write. I just wrote out an xunit fact doing
async void Foo()
and their analyzers didn't complain, but they could certainly add one that would. cc: @bradwilson -
Iain Carlin almost 4 yearsThanks, while not directly my problem, the tip to check the console output showed me the error (DBContext Dispose method had an error in it) that was preventing my tests from running.
-
Guillaume LaHaye almost 4 yearsI can't believe that this is still a problem... Hopefully, Microsoft with output some kind of warning for that classic snag at one point.
-
bkwdesign almost 4 yearsAfter switching from .NET Framework 4.6.2 to .NET Framework 4.7.2 - I had to delete all the binding redirects in app.config
-
Jen almost 4 yearsI had the opposite work for me. Changed from release to debug and got my green ticks
-
Christiano Kiss almost 4 yearsThis was my problem, too. In VS 2019, it doesn't seem to happen with Xunit, though. But it always occur when using MsTest +
async void
. -
Bob over 3 yearsInstalling NUnit3TestAdapter worked for me. I'm using VS 2019
-
JohnLBevan over 3 yearsThanks; I had a similar error; I'd mistyped a Parameter's name in the code I was testing... The test should have failed reporting that error; instead it showed as just not running.
-
mike gold over 3 yearsThis fixed it for me as well! I also kept trying and realized from this post that Microsoft seems to be adding the wrong reference to the project when you create an MSTest UnitTest and its not recognized when you run in Visual Studio. Thanks so much for figturing this out!
-
Stephen Holt over 3 years@BlueRaja-DannyPflughoeft - the missing Microsoft.NET.Test.Sdk was what was causing me problems. For some reason your comment was collapsed by StackOverflow, so I missed it initially. I've upvoted it now.
-
rjacobsen0 over 3 yearsYes! This was my problem. Thank you! I am using xUnit. I upgraded - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" /> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" /> And it started running my tests.
-
Pinte Dani over 3 yearsThis helped me also for MSTest, although I had to install MSTest.TestAdapter NuGet Package instead of NUnit TestAdapter
-
Jared Beach over 3 yearsFor me, I had to install the xunit test runner that matched my xunit version. Then restart visual studio. Then it worked
-
Guilherme de Jesus Santos over 3 yearsExactly the same situation I had issued. Installing xunit.runner.visualstudio fix the problem. My unit tests use xUnit, but Visual Studio said that nUnit Test Adapter could'nt find with that name. So installing this package solved it.
-
jkulpe about 3 yearsI had the same issue. I am in the middle of a code refactor and just a few tests were aborting due to this exception yet 160 of my 316 tests would not run at all. Further, if you run the nunit tests via the command line in PowerShell you'll see the StackOverFlow exception and can use that output to work on the debug
-
Russell Dow about 3 yearsI ran into a similar issue. TestContext needs to be a public property so the test runner can assign a new context to it.
-
rud0x1 about 3 yearsI just added "NUnit 3 Test Adaper" in Extensions Manager of my Visual Studio 2019. NUnit adapter has disappeared for some reasons. I remember that I already ran tests a month ago. ))
-
Chai about 3 yearsYou are answering to a very old questions that has many answers. Please make sure to contribute something there that adds a new solution or insights.
-
Bruno Martins almost 3 yearsI changed target framework from
netstandard2.0
tonet472
and it worked, thank you @MarcelStuder!! -
Dawood ibn Kareem almost 3 yearsThe fact that the tests run in the Resharper test runner indicates that there is no [Ignore] attribute on them.
-
JBSnorro almost 3 yearsYes, for example when upgrading to .NET 6; everything will still compile, but those packages need to be upgraded too
-
User1 almost 3 yearsThis fixed mine.. Just spent ages looking into this!
-
Zapnologica almost 3 yearsThis worked for me, a Great solution.. Our tests where just doing nothng. We removed those 2 and included the one and it worked perfectly.
-
Eric Hirst almost 3 yearsThis step appears to be necessary when you manually unload/edit/reload the xxx.test.csproj file in VS2019 using Power Commands.
-
Gustaf Liljegren over 2 yearsNice. I already had MS Test 2.x, but updating the test packages to the latest version (2.2.7) still fixed it for me.
-
rafael matovelle over 2 yearsThis works thanks.
-
this.myself over 2 yearsThe Test Output Log helped me to find an Exception deep down in Reactive Call Stack cause I had no mock for an Observable. Testing with Rx is quite challenging sometimes. But worth nonetheless.
-
Display name over 2 yearsI can confirm this works. At least for me. My tests were literally all working and then mid development they stopped and would not start. I tried several of the suggestions above: nothing. updating all the test packages restored function for me.
-
Ruli over 2 yearsYou are answering to a very old question that has many answers. Please make sure to contribute something that adds a new solution or insights.
-
pbell over 2 yearsThis was the issue for me when using XUnit, I needed to install xunit.runner.visualstudio
-
Matthew Conradie over 2 yearsThank you - this was my issue
-
Jeremy Caney about 2 yearsThere are sixty eight existing answers already, and several already mention this. Please upvote existing answers as a way of validating their feedback, instead of repeating their guidance.
-
Joel Wiklund about 2 yearsI had to close VS, then remove all bin and obj files and vs file, then start VS again, then it worked.
-
AyCe about 2 yearsOnly changing the Processor Architecture for AnyCPU Projects in the Test settings did not work, I (also?) had to change the PlatformTarget of the Test project.
-
Vinicius Bassi almost 2 yearsAdding the
[TestFixture]
attribute solved my problem