402

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.

16
  • 193
    Wouldn't it be wonderful if VS said why a test was not run? Mismatched target platform, missing test adapter, ... :( Commented Jan 21, 2020 at 9:39
  • 13
    Where is it mentioned they use ReSharper ? Commented Feb 1, 2020 at 14:35
  • 75
    @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. Commented Mar 4, 2020 at 5:24
  • 31
    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 Commented Jun 19, 2020 at 23:56
  • 7
    @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! Commented Apr 6, 2021 at 21:24

97 Answers 97

250

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.

Sign up to request clarification or add additional context in comments.

10 Comments

this one fixed my issues (switching from mixed platforms to anycpu)
make sure your testprojects are not netstandard2.0 but netcoreapp2.2
Worked. I really with VS would, you know, give us a clear warning or error message or something.
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.
VS2019 version: Main Menu -> Test -> Processor Architecture for AnyCPU Projects -> X64.
|
182

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

The tests were then active and runnable in Test Explorer.

8 Comments

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.
The facepalming I did when I read this echoed over the land... Thanks for pointing out my stupidity. That worked for me. Upvoted
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, 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
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.
|
158

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.

13 Comments

This helped me figure that that i needed to install the "NUnit 3 Test Adapter": marketplace.visualstudio.com/…
In VS 2019 worked for me to install the adapter from the package manager nuget.org/packages/NUnit3TestAdapter
According to this page you also need to install Microsoft.NET.Test.Sdk from Nuget
In VS 2019 I also installed the Extension Nunit 3 Test Adapter and it worked. One note: I also needed to update Visual Studio.
+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.
|
109

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

3 Comments

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.
This is a good way to troubleshoot the problem. In my case it was because... 'Method ClassCleanup has wrong signature'.
This helped me a lot. In my case the ClassInitialize method suddenly required a TestContext paramater, probably after a .NET version update at some point.
107

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

10 Comments

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 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.
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.
@lukka sometimes visual studio is the underlying problem and restarting is the solution
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.
|
49

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. Then I tried:

Step 1: Update the MSTest.TestAdapter and MSTest.TestFramework to version 2.0.0

Step 2: Now the Output console -> Test dropdown output started showing one after the other, missing packages and wrong binding redirects

Step 3: 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: Removed/Fixed the unnecessary binding redirects.

I hope this will help someone else.

5 Comments

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!
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.
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.
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.
Thank you so much! For me it was not the mstest adapter but a different version of NUnit3TestAdapter ! You brought me in the right direction!
40

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

5 Comments

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.
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
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!
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.
This one helped me - I had a project which was in v4.61 and it was migrated from old visual studio version - I had to stay on v4.61 which also meant that unittest project also should remain in v4.6.1 and this cause weird "refresh" issues like explained here - I then updated Microsoft.VisualStudio.QualityTools.UnitTestFramework to version 10.0.0.0 the one I had caused issues -- thanks for the help
40

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 Comments

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)
@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, 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.
22

Install Nunit3TestAdapter Nuget has solved this problem

1 Comment

this fixed my issue as well! :)
21

Clean-Rebuild solution worked for me.

Comments

18

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 Comment

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).
12

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

1 Comment

Yes, for example when upgrading to .NET 6; everything will still compile, but those packages need to be upgraded too
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 Comments

This was the fix for me, along with restarting VS and deleting the .vs folder. Thank you.
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.
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 Comments

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.
Solved: I have a .testsettings file. MSTest packages require a .runsettings file. That's why the tests aren't running.
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 Comment

It's 2022 and I still had this problem. Why can't VS identify this problem and tell us? :/
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 Comment

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.
8

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

1 Comment

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

enter image description here

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

Comments

7

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.

1 Comment

This is underrated brilliant answer - I had a problem in the config file which I could only see with this solution
6

For me, the issue was my ClassInit() method did not have the right signature.

MSTest class initialization and clean-up attributes

In particular, note the [ClassInitialize] attribute on the ClassInit() method.

Works:

[ClassInitialize]
public static void ClassInit(TestContext context)
{

}

Did Not Work:

[ClassInitialize]
public void ClassInit(TestContext context)
{

}

or

[ClassInitialize]
public static void ClassInit()
{

}

or

[ClassInitialize]
public void ClassInit()
{

}

1 Comment

This was my issue too, because I didn't need to touch TestContext context I was getting a warning in the IDE so I removed it. Which causes the tests to not run :facepalm:. So to fix it I added a SuppressMessage attribute for IDE00600 for the ClassInit function.
5

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

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

Comments

5

This issue is also observed when the test method being run throws a StackOverflowException, making the test runner abort the test run, resulting in the output 0 tests run.

To find the culprit and solve it put a break point at the start of both TestInitialize and TestMethod decorated methods, run the unit test in debug mode, proceed stepping over (F10) until the exception is thrown.

1 Comment

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
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)

Comments

5

If you are using NUnit, please make sure to add the nuget package enter image description here

Note that use of VSIX Test adapters are deprecated in VS 2019, we recommend you to use the nuget versions of the adapter. this is from https://marketplace.visualstudio.com/items?itemName=NUnitDevelopers.NUnit3TestAdapter

Comments

4

Since I got here with this kind of error I post my problem/solution:

Symptoms:

  • Not all tests running, but they didn't depend per project, just some of them were executed.
  • All executed ones were green.
  • Tech stack: dotnet core / XUnit / FluentAssertions
  • All tests detected and updated if it changed.
  • By selection or running "Not runned tests" several times they could be executed.

Problem:

There was an error in the code that throw an exception inside another thread. All test assertions passed but it cancelled the test execution. I could see the error in the "Tests output" (NullException).

1 Comment

+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.
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.

Comments

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 Comment

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

Comments

4

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

1 Comment

I had the opposite work for me. Changed from release to debug and got my green ticks
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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.