Tests not running in Test Explorer

248,857

Solution 1

If your projects aren't all AnyCpu then you may also want to check that the following 2 settings match:

  1. [Right click test project] -> properties -> Build -> Platform target - e.g. x64

  2. [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

  1. 5 Unit test projects, all discoverable in TestExplorer
  2. 2 out of 5 executed properly
  3. 3 stating not run at all
  4. 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

  1. System.Runtime.Extentions
  2. System.Reflection
  3. 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.

Share:
248,857

Related videos on Youtube

ElGauchooo
Author by

ElGauchooo

Updated on April 08, 2022

Comments

  • ElGauchooo
    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:

    enter image description here

    • 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 and Release folders

    I'd appreciate any hints which would explain this behaviour.

    • kmhigashioka
      kmhigashioka over 9 years
      Update your ReSharper. Refer to this stackoverflow.com/questions/16011775/…
    • Bernhard Hofmann
      Bernhard Hofmann over 4 years
      Wouldn't it be wonderful if VS said why a test was not run? Mismatched target platform, missing test adapter, ... :(
    • Alex 75
      Alex 75 over 4 years
      Where is it mentioned they use ReSharper ?
    • JLRishe
      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
      Kyle Delaney about 4 years
      You all might be interested in upvoting this feature request: developercommunity.visualstudio.com/idea/947742/…
    • hk1ll3r
      hk1ll3r almost 4 years
      Year 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
      Werner Bisschoff almost 4 years
      So, 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
      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
      profimedica over 2 years
      @hk1ll3r, can you share that project bit that does not run?
    • Stefan Varga
      Stefan Varga over 2 years
      I 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
    Steve Rakebrandt over 7 years
    Uninstall Resharper?! I don't think that this is a solution^^
  • lukkea
    lukkea almost 6 years
    my 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
    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
    Westerlund.io over 5 years
    This helped me figure that that i needed to install the "NUnit 3 Test Adapter": marketplace.visualstudio.com/…
  • Marcel Studer
    Marcel Studer almost 5 years
    this one fixed my issues (switching from mixed platforms to anycpu)
  • user2033412
    user2033412 almost 5 years
    make sure your testprojects are not netstandard2.0 but netcoreapp2.2
  • Palle Due
    Palle Due almost 5 years
    In 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
    Palle Due almost 5 years
    Solved: I have a .testsettings file. MSTest packages require a .runsettings file. That's why the tests aren't running.
  • anon
    anon almost 5 years
    Worked. I really with VS would, you know, give us a clear warning or error message or something.
  • Halvard
    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
    JamesHoux over 4 years
    Temporarily 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
    maylon over 4 years
    In VS 2019 worked for me to install the adapter from the package manager nuget.org/packages/NUnit3TestAdapter
  • Ketobomb
    Ketobomb over 4 years
    There 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
    Numan over 4 years
    You 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
    Donald.Record over 4 years
    This was the fix for me, along with restarting VS and deleting the .vs folder. Thank you.
  • J_L
    J_L over 4 years
    This 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
    Éric Bergeron over 4 years
    After 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
    StackOverthrow over 4 years
    VS2019 version: Main Menu -> Test -> Processor Architecture for AnyCPU Projects -> X64.
  • Eru
    Eru over 4 years
    this fixed my issue as well! :)
  • BlueRaja - Danny Pflughoeft
    BlueRaja - Danny Pflughoeft over 4 years
    According to this page you also need to install Microsoft.NET.Test.Sdk from Nuget
  • Richard Garside
    Richard Garside over 4 years
    If 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
    Bob Lokerse about 4 years
    In VS 2017 I installed the Extension Nunit 3 Test Adapter and it worked.
  • Bob Lokerse
    Bob Lokerse about 4 years
    In VS 2019 I also installed the Extension Nunit 3 Test Adapter and it worked. One note: I also needed to update Visual Studio.
  • Samiron
    Samiron about 4 years
    I wish I could give you a bunch of likes. Thanks a lot.
  • Adam Cox
    Adam Cox about 4 years
    Note 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
    jr-juxtaposition about 4 years
    This 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
    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
    JSON about 4 years
    @lukka sometimes visual studio is the underlying problem and restarting is the solution
  • benmccallum
    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
    ebyrob about 4 years
    I 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
    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
    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
    JP Chapleau almost 4 years
    The facepalming I did when I read this echoed over the land... Thanks for pointing out my stupidity. That worked for me. Upvoted
  • pat8719
    pat8719 almost 4 years
    Although 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
    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
    Iain Carlin almost 4 years
    Thanks, 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
    Guillaume LaHaye almost 4 years
    I 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
    bkwdesign almost 4 years
    After 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
    Jen almost 4 years
    I had the opposite work for me. Changed from release to debug and got my green ticks
  • Christiano Kiss
    Christiano Kiss almost 4 years
    This 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
    Bob over 3 years
    Installing NUnit3TestAdapter worked for me. I'm using VS 2019
  • JohnLBevan
    JohnLBevan over 3 years
    Thanks; 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
    mike gold over 3 years
    This 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
    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
    rjacobsen0 over 3 years
    Yes! 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
    Pinte Dani over 3 years
    This helped me also for MSTest, although I had to install MSTest.TestAdapter NuGet Package instead of NUnit TestAdapter
  • Jared Beach
    Jared Beach over 3 years
    For 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
    Guilherme de Jesus Santos over 3 years
    Exactly 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
    jkulpe about 3 years
    I 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
    Russell Dow about 3 years
    I ran into a similar issue. TestContext needs to be a public property so the test runner can assign a new context to it.
  • rud0x1
    rud0x1 about 3 years
    I 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
    Chai about 3 years
    You 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
    Bruno Martins almost 3 years
    I changed target framework from netstandard2.0 to net472 and it worked, thank you @MarcelStuder!!
  • Dawood ibn Kareem
    Dawood ibn Kareem almost 3 years
    The fact that the tests run in the Resharper test runner indicates that there is no [Ignore] attribute on them.
  • JBSnorro
    JBSnorro almost 3 years
    Yes, for example when upgrading to .NET 6; everything will still compile, but those packages need to be upgraded too
  • User1
    User1 almost 3 years
    This fixed mine.. Just spent ages looking into this!
  • Zapnologica
    Zapnologica almost 3 years
    This 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
    Eric Hirst almost 3 years
    This step appears to be necessary when you manually unload/edit/reload the xxx.test.csproj file in VS2019 using Power Commands.
  • Gustaf Liljegren
    Gustaf Liljegren over 2 years
    Nice. 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
    rafael matovelle over 2 years
    This works thanks.
  • this.myself
    this.myself over 2 years
    The 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
    Display name over 2 years
    I 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
    Ruli over 2 years
    You 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
    pbell over 2 years
    This was the issue for me when using XUnit, I needed to install xunit.runner.visualstudio
  • Matthew Conradie
    Matthew Conradie over 2 years
    Thank you - this was my issue
  • Jeremy Caney
    Jeremy Caney about 2 years
    There 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
    Joel Wiklund about 2 years
    I had to close VS, then remove all bin and obj files and vs file, then start VS again, then it worked.
  • AyCe
    AyCe about 2 years
    Only 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
    Vinicius Bassi almost 2 years
    Adding the [TestFixture] attribute solved my problem