350

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.

14
  • 5
    Update your ReSharper. Refer to this stackoverflow.com/questions/16011775/… Jan 14, 2015 at 0:30
  • 150
    Wouldn't it be wonderful if VS said why a test was not run? Mismatched target platform, missing test adapter, ... :( Jan 21, 2020 at 9:39
  • 9
    Where is it mentioned they use ReSharper ?
    – Alex 75
    Feb 1, 2020 at 14:35
  • 64
    @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.
    – JLRishe
    Mar 4, 2020 at 5:24
  • 16
    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
    – hk1ll3r
    Jun 19, 2020 at 23:56

86 Answers 86

235

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.

9
  • this one fixed my issues (switching from mixed platforms to anycpu) Aug 2, 2019 at 6:37
  • 2
    make sure your testprojects are not netstandard2.0 but netcoreapp2.2 Aug 12, 2019 at 11:29
  • 6
    Worked. I really with VS would, you know, give us a clear warning or error message or something.
    – anon
    Aug 22, 2019 at 14:09
  • 1
    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.
    – JamesHoux
    Aug 30, 2019 at 1:37
  • 47
    VS2019 version: Main Menu -> Test -> Processor Architecture for AnyCPU Projects -> X64. Jan 17, 2020 at 22:03
147

I had to change my async test methods to return Task instead of void.

The tests were then active and runnable in Test Explorer.

7
  • 7
    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.
    – Ketobomb
    Dec 5, 2019 at 8:39
  • 13
    The facepalming I did when I read this echoed over the land... Thanks for pointing out my stupidity. That worked for me. Upvoted Jun 4, 2020 at 18:09
  • 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.
    – pat8719
    Jun 14, 2020 at 16:51
  • 2
    @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 Jun 16, 2020 at 8:52
  • 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. Aug 20, 2020 at 8:23
134

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.

11
  • 15
    This helped me figure that that i needed to install the "NUnit 3 Test Adapter": marketplace.visualstudio.com/… Nov 25, 2018 at 15:44
  • 14
    In VS 2019 worked for me to install the adapter from the package manager nuget.org/packages/NUnit3TestAdapter
    – maylon
    Aug 30, 2019 at 20:08
  • 7
    According to this page you also need to install Microsoft.NET.Test.Sdk from Nuget Feb 10, 2020 at 10:04
  • 2
    In VS 2019 I also installed the Extension Nunit 3 Test Adapter and it worked. One note: I also needed to update Visual Studio. Mar 4, 2020 at 9:32
  • 2
    +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.
    – Nele Kosog
    May 13, 2020 at 11:18
95

I had the same problem in VS 2017. In my case it solved by restarting VS.

8
  • 17
    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.
    – lukkea
    Jul 27, 2018 at 8:26
  • 13
    @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.
    – Sascha
    Nov 9, 2018 at 6:03
  • 7
    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. Feb 21, 2020 at 14:23
  • 15
    @lukka sometimes visual studio is the underlying problem and restarting is the solution
    – JSON
    Apr 8, 2020 at 13:59
  • 2
    Revisiting this thread every few years. This time I had VS 2022 17.4.0, all projects using x64, and I tried all the other tips here. Tests would not run. Restarting VS2022 resolved it immediately. No files were deleted. Dec 6, 2022 at 12:14
70

You can view the error-output of your test runner by opening the Output panel (view-->output) and choosing "tests" from the "Show output from" dropdown

show output from


Additionally, if you have Resharper installed you can open a test file and hover over the test-circle next to a test to get additional error info

Resharper output

Clicking that will bring you to a window with more detailed information. Alternatively, you can open that window by going to Extensions --> Reshaper --> Windows --> Unit Test Exploration Results

Resharper Unit Test Exploration

2
  • 2
    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. Oct 21, 2021 at 15:36
  • 2
    This is a good way to troubleshoot the problem. In my case it was because... 'Method ClassCleanup has wrong signature'.
    – xSquared
    Jun 13, 2022 at 12:32
44

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.

4
  • 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!
    – Numan
    Dec 18, 2019 at 16:38
  • 1
    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.
    – ebyrob
    Apr 9, 2020 at 18:21
  • 3
    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. Jul 2, 2020 at 0:31
  • 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. Sep 27, 2021 at 8:21
38

Check what framework the tests are written against (e.g. nunit, xunit, VS test, etc.) and make sure you've got the correct test adapter/runner extension installed.

For me it was NUnit 3 Test Adapter that was missing and I confirmed the version number required by looking at the nunit.framework dependency version (select the .dll in the Dependencies tree in Solution Explorer and hit F4 to bring up the Properties window).

3
  • 6
    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)
    – Adam Cox
    Mar 23, 2020 at 14:45
  • @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.
    – ebyrob
    Apr 7, 2020 at 15:32
  • @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. Apr 9, 2020 at 18:00
36

I found that in the project it was not referencing the Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly. Instead, it was referencing Microsoft.VisualStudio.TestPlatform.TestFramework and Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions. When I removed those two references and added the reference to the Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly the tests that were previously marked with the blue exclamation point suddenly became active and started working.

Unit tests not run with wrong assembly

With the right assembly, the tests run

4
  • 4
    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. Jan 8, 2020 at 15:13
  • 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
    – bkwdesign
    Jul 31, 2020 at 15:38
  • 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!
    – mike gold
    Oct 14, 2020 at 18:39
  • 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. Aug 6, 2021 at 7:00
20

Install Nunit3TestAdapter Nuget has solved this problem

1
  • 1
    this fixed my issue as well! :)
    – Eru
    Jan 22, 2020 at 14:47
19

Clean-Rebuild solution worked for me.

17

I had this issue and for me it was caused by having multiple Test Projects with different versions of :

  • MSTest.TestAdapter
  • MSTest.TestFramework

Consolidating the nuget packages for the projects so they were the same resolved the issue for me.

1
  • 1
    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). Apr 2, 2020 at 15:23
12

What fixed it for me was upgrading the MS.Test nuget packages

1
  • Yes, for example when upgrading to .NET 6; everything will still compile, but those packages need to be upgraded too
    – JBSnorro
    Jul 23, 2021 at 11:36
12

Had same issue after clean install of VS 2019. Tests are found but not run with "Unexpected error occurred". Fixed by setting up x64 instead of x86 which was selected by default.

enter image description here

2
  • 6
    This was the fix for me, along with restarting VS and deleting the .vs folder. Thank you. Dec 30, 2019 at 17:33
  • 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. Jul 31, 2020 at 6:04
10

In my case, it was because one test project in my solution had the MSTest.TestFramework and MSTest.TestAdapter nuget packages installed but the others did not. These packages were apparently not required to run tests until one project in the solution had them installed.

The issue was fixed by installing those packages on test projects missing them.

2
  • 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
    Aug 15, 2019 at 7:32
  • 1
    Solved: I have a .testsettings file. MSTest packages require a .runsettings file. That's why the tests aren't running.
    – Palle Due
    Aug 15, 2019 at 7:47
8

In my case I had an async void Method and I replaced with async Task ,so the test run as i expected :

    [TestMethod]
    public async  void SendTest(){}

replace with :

    [TestMethod]
    public async  Task SendTest(){}
1
  • It's 2022 and I still had this problem. Why can't VS identify this problem and tell us? :/
    – ibrahimijc
    Jul 21, 2022 at 16:51
8

Have tried many options with Visual Studio 2019 Version 16.4.6 and Microsoft.VisualStudio.TestTools.UnitTesting, but for now the only way to run tests successfully was by invoking next command in console

dotnet test

Tests are discovered in Test Explorer but outcome is "Not Run".

Updating Visual Studio did not help.

Have resolved issue with "No test matches the given testcase filter FullyQualifiedName" by running updates to latest version for next packages:

Microsoft.NET.Test.Sdk
MSTest.TestAdapter
MSTest.TestFramework
1
  • 1
    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.
    – rjacobsen0
    Nov 23, 2020 at 15:02
7

enter image description here

Setting Processor Architecture for AnyCPU Projects in Test Explorer fixed my issue! See screenshot above.

0
7

I am using XUnit and was missing the xunit.runner.visualstudio package. Installing it and my tests ran.

1
  • 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. Feb 12, 2021 at 12:56
5

I managed to figure out the reason for VS 2019/2022 skipping some tests by running the test cli with blame option:

vstest.console.exe myproject-test.dll /blame

This will generate an xml file with one test with "Completed="False".

In my case, the test host process crashed due to a memory access violation while running that test. The memory access violation was caused by an infinite recursion. You can right-click and debug that certain test.

0
5

With Visual Studio 2019 and test project targeting .NET 5.0 you need to install also xunit.runner.visualstudio. So, your packages should be like in this example:

  • xunit (2.4.1)
  • xunit.runner.visualstudio (2.4.3)
1
4

I had different version of NUnit (3.11.0) and NunitTestAdapter (3.12.0) nuget packages. When I updated NUnit to 3.12.0, Visual Studio ran tests.

4

In my case it worked to update the MSTest nuget packages. Could reproduce this problem even on blank MSTest project and updating the packages worked.

1
  • 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. Nov 23, 2021 at 22:42
4

Had the same symptoms, in my case it was the dotnet core SDK version that was the problem.

The projects was targeting 2.2, and was able to build using 3.0. After installing newest 2.2 SDK version they were able to run.

4

I changed "Debug" to "Release" and it worked again (Any CPU.)

1
  • I had the opposite work for me. Changed from release to debug and got my green ticks
    – Jen
    Aug 5, 2020 at 3:42
4

I had a different solution to get my tests to run. My global packages folder didn't match what was in my .csproj This is what my .csproj looked like: UnitTest .csproj

I had to change my Version to 16.5.0 which i found was installed in my global packages folder. Now my tests are able to run: .nuget folder explorer

4

What works for me is to delete the bin folder, then rebuild the project.

0
4

After struggling for hours on VS 2022, the solution for me was to install both: NUnit and NUnit3TestAdapter nuget packages

enter image description here

4

When using both MSTests and NUnit tests it is possible to mix them. Also, remove other testing frameworks NuGet packages. Remove, Clean solution, Rebuild

This is the case:

[TestFixture]
public class NUnitTestClass
{
    [TestMethod]
    public void MSTestMethod()
    {
         // Will detect it but it won't run
    }
}
1
  • Adding the [TestFixture] attribute solved my problem May 31, 2022 at 18:40
3

I had same symptoms.

Please ensure you have the proper Visual Studio extension installed via Tools - Extensions and Updates. In my case, I had to install XUnit and Specflow from the Online option.

Then clean the solution and rebuild it.

If that still doesn't help, clear your temp directory (search for %temp% in the Start menu search and delete all contents in Temp)

And then finally try uninstalling Resharper which finally fixed my problem.

1
  • 4
    Uninstall Resharper?! I don't think that this is a solution^^ Jan 20, 2017 at 10:52
3

Here it was the test project was not marked to be built:

Build -> Configuration Manager... -> check build for your test project

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.