360

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.

Philip Raath
  • 460
  • 3
  • 18
ElGauchooo
  • 4,256
  • 2
  • 13
  • 16
  • 5
    Update your ReSharper. Refer to this http://stackoverflow.com/questions/16011775/vs2012-doesnt-run-unit-tests?rq=1 – kmhigashioka Jan 14 '15 at 00:30
  • 162
    Wouldn't it be wonderful if VS said *why* a test was not run? Mismatched target platform, missing test adapter, ... :( – Bernhard Hofmann Jan 21 '20 at 09:39
  • 10
    Where is it mentioned they use ReSharper ? – Alex 75 Feb 01 '20 at 14:35
  • 68
    @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 04 '20 at 05:24
  • 4
    You all might be interested in upvoting this feature request: https://developercommunity.visualstudio.com/idea/947742/unit-tests-should-provide-a-reason-when-a-test-is.html – Kyle Delaney Mar 12 '20 at 22:55
  • 17
    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 '20 at 23:56
  • 2
    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 i had ?xml version="1.0" encoding="utf-8"?> – Werner Bisschoff Jul 20 '20 at 08:51
  • 5
    @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! – Ken Lyon Apr 06 '21 at 21:24
  • 1
    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 – Stefan Varga Feb 07 '22 at 14:48
  • Encountered this today because I had decorated an internal method with [TestInitialize]. Changed access modifier to public and the tests ran again. This post did not answer my question but helped me eliminate possibilities! – nothingisnecessary Jun 07 '22 at 07:29
  • In vs 2022, this issue happened when I created `async void` test method rather than `async Task` – Ahmed Abd Elmoniem Jul 28 '22 at 20:26
  • Similar issue in VS 2022 .net6 project. Problem was that I didn't specify namespace (which is possible with file-scoped namespaces). Once namespace was specified at the top of the file, tests run in TestExplorer with no problem. – Roman Gudkov Aug 26 '22 at 16:19
  • In my case the .NET Test Project compiled but would just show Not Run in Test Explorer. Seems one of the other projects it was referencing needed Microsoft.AspNetCore.Mvc.Core and cause it wasn't added to this test project it would just "not load" for testing. No indication of what package it was missing though. So painful. – AussieALF Jan 20 '23 at 05:58
  • Is your project under test targeting NetStandardx.x? If so, and you used Create Unit Test, the test project is set up to use NetStandard and tests are not exected. Change the test project target to Net7.0 or similar. – balintn Feb 06 '23 at 20:28

88 Answers88

239

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.

Joseph Simpson
  • 4,054
  • 1
  • 24
  • 28
152

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

The tests were then active and runnable in Test Explorer.

Kevin Mills
  • 1,639
  • 1
  • 10
  • 10
  • 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 05 '19 at 08: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 – JP Chapleau Jun 04 '20 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 '20 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 – benmccallum Jun 16 '20 at 08: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`. – Christiano Kiss Aug 20 '20 at 08:23
  • This fixed mine.. Just spent ages looking into this! – JKennedy Aug 02 '21 at 09:36
  • This solved it for me when converting from xunit to MSTest. xUnit _can_ work with `async void` methods. – asontu Dec 15 '22 at 12:01
141

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.

malat
  • 12,152
  • 13
  • 89
  • 158
Piers Myers
  • 10,611
  • 6
  • 46
  • 61
  • 15
    This helped me figure that that i needed to install the "NUnit 3 Test Adapter": https://marketplace.visualstudio.com/items?itemName=NUnitDevelopers.NUnit3TestAdapter – Westerlund.io Nov 25 '18 at 15:44
  • 14
    In VS 2019 worked for me to install the adapter from the package manager https://www.nuget.org/packages/NUnit3TestAdapter/ – maylon Aug 30 '19 at 20:08
  • 8
    According to [this page](https://github.com/microsoft/vstest/issues/1870) you also need to install `Microsoft.NET.Test.Sdk` from Nuget – BlueRaja - Danny Pflughoeft Feb 10 '20 at 10:04
  • In VS 2017 I installed the Extension Nunit 3 Test Adapter and it worked. – Bob Lokerse Mar 04 '20 at 09:21
  • 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. – Bob Lokerse Mar 04 '20 at 09: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 '20 at 11:18
  • 1
    Installing NUnit3TestAdapter worked for me. I'm using VS 2019 – Bob Sep 08 '20 at 15:25
  • @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. – Stephen Holt Nov 16 '20 at 13:08
  • This helped me also for MSTest, although I had to install MSTest.TestAdapter NuGet Package instead of NUnit TestAdapter – Pinte Dani Dec 03 '20 at 18:27
  • 1
    This was the issue for me when using XUnit, I needed to install xunit.runner.visualstudio – pbell Jan 19 '22 at 22:07
  • This got me on the right path but I needed to install the "NUnit.Console" from the package manager as well – Paul Matovich Oct 24 '22 at 12:35
99

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

Pablo Rausch
  • 1,284
  • 9
  • 6
  • 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 '18 at 08:26
  • 14
    @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 09 '18 at 06: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. – Richard Garside Feb 21 '20 at 14:23
  • 18
    @lukka sometimes visual studio is the underlying problem and restarting is the solution – JSON Apr 08 '20 at 13:59
  • For me, I had to install the xunit test runner that matched my xunit version. Then restart visual studio. Then it worked – Jared Beach Jan 14 '21 at 17:10
  • This step appears to be necessary when you manually unload/edit/reload the xxx.test.csproj file in VS2019 using Power Commands. – Eric Hirst Aug 10 '21 at 22:02
  • I had to close VS, then remove all bin and obj files and vs file, then start VS again, then it worked. – Joel Wiklund Mar 01 '22 at 09:26
  • 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. – Dan Gøran Lunde Dec 06 '22 at 12:14
77

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

BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
  • 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. – this.myself Oct 21 '21 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 '22 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.

JohnB
  • 18,046
  • 16
  • 98
  • 110
Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61
  • 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 '19 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 09 '20 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. – Iain Carlin Jul 02 '20 at 00: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. – Gustaf Liljegren Sep 27 '21 at 08:21
39

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

benmccallum
  • 1,241
  • 12
  • 27
  • 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 '20 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 07 '20 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. – benmccallum Apr 09 '20 at 18:00
37

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

markdotnet
  • 2,496
  • 2
  • 19
  • 12
  • 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. – Éric Bergeron Jan 08 '20 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 '20 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 '20 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. – Zapnologica Aug 06 '21 at 07:00
20

Install Nunit3TestAdapter Nuget has solved this problem

AvishalomJan
  • 391
  • 3
  • 3
19

Clean-Rebuild solution worked for me.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Eugene Ihnatsyeu
  • 1,299
  • 13
  • 15
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.

Jon Ryan
  • 1,497
  • 1
  • 13
  • 29
  • 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). – jr-juxtaposition Apr 02 '20 at 15:23
12

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

user2945722
  • 1,293
  • 1
  • 16
  • 35
  • Yes, for example when upgrading to .NET 6; everything will still compile, but those packages need to be upgraded too – JBSnorro Jul 23 '21 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

Vadim Leb
  • 731
  • 7
  • 6
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.

SteveC
  • 398
  • 1
  • 5
  • 11
  • 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 '19 at 07: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 '19 at 07: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(){}
Ali Besharati
  • 918
  • 12
  • 25
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
volody
  • 6,946
  • 3
  • 42
  • 54
7

enter image description here

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

dotnet-provoke
  • 1,308
  • 14
  • 25
7

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

reZach
  • 8,945
  • 12
  • 51
  • 97
  • 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. – Guilherme de Jesus Santos Feb 12 '21 at 12:56
6

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.

felixh
  • 379
  • 2
  • 7
  • This is underrated brilliant answer - I had a problem in the config file which I could only see with this solution – amarax Sep 01 '23 at 10:13
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)
ElConrado
  • 1,477
  • 4
  • 20
  • 46
5

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

}
JohnB
  • 18,046
  • 16
  • 98
  • 110
  • 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. – Rocklan Jun 07 '23 at 02:20
4

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

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

CountOren
  • 844
  • 1
  • 9
  • 27
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.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
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.

CodingYourLife
  • 7,172
  • 5
  • 55
  • 69
  • 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. – Display name Nov 23 '21 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.

Kristoffer la Cour
  • 2,591
  • 3
  • 25
  • 36
4

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

vali
  • 71
  • 5
  • I had the opposite work for me. Changed from release to debug and got my green ticks – Jen Aug 05 '20 at 03: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

Katelyn Rochat
  • 111
  • 1
  • 4
4

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

sierra
  • 41
  • 1
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
    }
}
profimedica
  • 2,716
  • 31
  • 41
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

Umar T.
  • 411
  • 6
  • 11
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.

Gina
  • 31
  • 3
3

Check in your project file for references to NUnit of different versions:

In my case, I had installed version 3.11.0 of both NUnit and NUnit3TestAdapter, but there were old references to version 2.6.4, in the project file, that weren't removed with the new installation.

  • Solution (Recomended to fix references issues, see docs):

    Reinstall NUnit and NUnit3TestAdapter, this fixed the references in my project.
PM> Update-Package NUnit -reinstall
...
PM> Update-Package NUnit3TestAdapter -reinstall
  • Solution 2 (In case of reinstalling didn't fix the references):

    Uninstall and install NUnit and NUnit3TestAdapter.
PM> Uninstall-Package NUnit
...
PM> Uninstall-Package NUnit3TestAdapter
...
PM> Install-Package NUnit
...
PM> Install-Package NUnit3TestAdapter
Yasel
  • 2,920
  • 4
  • 40
  • 48
3

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.

Thomas C. G. de Vilhena
  • 13,819
  • 3
  • 50
  • 44
  • 1
    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 – jkulpe Mar 12 '21 at 14:34
3

I had a slightly different scenario, but this is the top Google result so I'll answer my issue too. I could run the tests but only about half of them actually ran, with no error output.

Eventually I debugged and stepped through all the tests, and came upon a Stack Overflow Error when creating Test Instances of some models.

In the test instance methods, a child model created a parent and the parent created a child, which created an infinite loop. I removed the parent creation from the child, and now all my tests work!

James L.
  • 12,893
  • 4
  • 49
  • 60
  • 1
    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. – JohnLBevan Sep 11 '20 at 12:28
3

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

Nayanava
  • 69
  • 1
  • 6
2

For me solution was to change the Resharper Unit Testing settings "Default platform architecture" to "x64"

enter image description here

Dharmesh Tailor
  • 320
  • 1
  • 11
  • 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. – J_L Jan 07 '20 at 20:07
2

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

OriolBG
  • 2,031
  • 2
  • 18
  • 21
  • +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. – Halvard Aug 29 '19 at 12:50
2

For me having a property called TestContext in a base class was causing this behavior. For example:

[TestClass]
public abstract class TestClassBase
{
    protected object TestContext { get; private set; }
}

[TestClass]
public class TestClass : TestClassBase
{
    // This method not found
    [TestMethod]
    public void TestCase() {}
}
Uni
  • 21
  • 1
2

There are already a lot of answers to this question, but I had a different scenario and resolution.

We moved functionality of a type being tested from one class to a new class, and as such created a new test class, with the old test class ending up being empty.

Original:

  • Old test class
    • Test initialize method
    • Test methods

Broken:

  • Old test class (initializer kept, class kept as placeholder for future)
    • Test initialize method (remains, by itself)
    • No test methods (the original test methods appear in test runner but don't exist in code so never execute)
  • New test class
    • Test initialize method
    • Test methods

Fixed:

  • Old test class (removed)
  • New test class
    • Test initialize method
    • Test methods

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

Jon Davis
  • 6,562
  • 5
  • 43
  • 60
  • "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 :) – Stephan Møller May 15 '20 at 10:18
2

I added <PackageReference Include="NUnit3TestAdapter" Version="3.16.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference>

in my Test.csproj file

Quince Ngomane
  • 340
  • 1
  • 3
  • 16
  • 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. )) – rud0x1 May 12 '21 at 14:34
2

Maybe it's an Infinite Loop.

Almost half of my tests were not running. The new changes I made to the code brought the tests to create an infinite loop. After fixing this issue (adding the correct arguments to the right method call) every test ran normally.

Hope this can help anyone - if you're adding new logic to someone else's code try debugging the tests that are not running, maybe you ran into an infinite loop too and VS just stopped the tests.

João Páris
  • 51
  • 1
  • 4
2

(I see this question already has many answers, but I couldn't find my scenario here.)

In my case (xUnit), the clue was in Visual Studio's "Test" output log (see screenshot below).

My NuGet packages were all updated - latest versions - to the point where I needed a (slightly 6.0.13 vs 6.0.12) newer version of .NET, which I didn't have installed.

I updated Visual Studio and managed to run the tests.

Tests fail because of .NET version

user1987392
  • 3,921
  • 4
  • 34
  • 59
2

In my case (VS 2022) - I installed MSTest.TestFramework first and could see the tests in test explorer, but they only went build and then nothing.

I performed the following steps until the problem was resolved:

  1. Update the project platform target to be x64
  2. Update the default CPU architecture to be X64
  3. I installed MsTest.TestAdapter
  4. I installed the Microsoft.Net.Test.SDK And only after all the above steps, my tests started running properly.

Note: After the problem was resolved, I reverted steps 1 & 2 back to how they were at the beginning, and the tests still ran fine, So probably in my case this thing was not necessary.

Pessie Ma
  • 21
  • 1
1

For me restarting VS2017 did not work. I had to clean sln then found a file with tests that didn't run and run that file only. After that I did run all and it worked normal again.

Ray
  • 12,101
  • 27
  • 95
  • 137
1

For me (not quite a solution) it was deselecting the .testsettings file in the Menu [Test]->[Test Settings]->[{current File}] to uncheck the currently used file.

In my case it starts so.

<TestSettings name="Local (with code coverage)" id="e81d13d9-42d0-41b9-8f31-f719648d8d2d" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <Deployment>
    <DeploymentItem filename="ConfigurationImportExportTest\Configurations\" />
    <DeploymentItem filename="output\Debug\" />
  </Deployment>
  <Execution>

Apparently the DeploymentItem interferes.

because this was in the Output tab:

Warning: Test Run deployment issue: The assembly or module 'Microsoft.SqlServer.Management.SqlParser' directly or indirectly referenced by deployment item 'output\Debug\' specified by the test settings was not found.
.... more of the same

It does not tell me lots.
Seems like it has to do with the way that all projects put their compilation products in a common \output\Debug folder

however that seems not to hinder it. It puts out another warning mentioning things like

A testsettings or runsettings file with `ForcedLegacyMode = TRUE or VSMDI files are not supported by MSTest-V2.

That seems to stop it.

Robetto
  • 739
  • 7
  • 20
1

I can tell from your attributes that you're using MSTest. I had a similar issue: my tests were showing up in the Test Explorer, but when I would try to run them (either by choosing Run All or individually selecting them) they would not.

My problem was that I had created the unit test project manually from an empty .NET Standard Class Library project. I had installed the MSTest.TestFramework NuGet package, but not the MSTest.TestAdapter package. As soon as I installed the adapter package, they ran as expected.

Seems obvious in retrospect, but when you create unit test projects from a template, you take these things for granted.

bobm
  • 33
  • 7
1

It is worth mentioning that sometimes NUnit Test Adapter files get corrupted in user folder C:\Users[User]\AppData\Local\Temp\VisualStudioTestExplorerExtensions\NUnit3TestAdapter.3.8.0/build/net35/NUnit3.TestAdapter.dll on Windows 10 and that causes Test Explorer to stop working as it should.

1

I use VS2019 with .Net 4.7. I installed NUnit extension v3, and changed the Test settings to use X64. My unit test project is Any CPU (would work if I changed it to x64). Now I can debug through my code.

Rez.Net
  • 1,354
  • 2
  • 19
  • 28
1

Well i know i am late to the party, but logging my answer here , incase, someone is facing similar issue as mine. I have faced this issue many times. 90% it gets solved by these two steps

project > properties > Build > Platform target > x64 (x32)

Test -> Test Settings > Default Processor Architecture > X64 (x32)

However i found one more common cause. The Solution files often change developer systems and they start pointing to wrong MSTest.TestAdapter. Especially if you are using custom path of nuget packages. I solved this issue by

  1. Opening the .csproj file in notepad.

  2. Manually correcting reference to MSTest.TestAdapter in import instructions like this.

amarnath chatterjee
  • 1,942
  • 16
  • 15
1

Please make sure that you choose the right type of project. In my case, I chose the 'Unit Test Project' and I should have 'xUnit Test Project'. enter image description here

syp_dino
  • 395
  • 3
  • 10
1

This problem occurred for me when creating a separate test project within Visual Studio 2022 for Mac (preview).

  • Repro Steps:
    • Open project in VS 2022
    • right click on solution, add new project
    • tests > nunit > continue
    • Target Framework: NET 6.0
    • Name : random-tests > create
    • VS 2022 for mac inclues a dependency for coverlet.collector - deleting this nuget reference fixed the problem for me.

solution-explorer

Thomas
  • 550
  • 5
  • 17
1

The answer is:

Embedd NUnit3TestAdapter as Nuget Package additionally to NUnit. Thank me later

1

Trivial but in my case, tests did not run because the constructor was private.

I found this under Tests in the Output window.

Amit
  • 348
  • 1
  • 6
  • 12
1

Check Build for your Application Test at Configuration Manager:

screenshot

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • 3
    Welcome to Stack Overflow! Thank you for contributing an answer. Could you please [edit] it to clarify what to look for in this screenshot and why this would solve the problem at the top of the page? See [answer]. – Adriaan Mar 22 '23 at 07:01
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 26 '23 at 10:39
0

For me this was caused by a VS extension for measuring code coverage. It could not reference a particular assembly, and therefore would not run any of the tests. Tests would run fine from the command line using:

dotnet test

To solve this issue, you can opt to have ALL dependencies copied to your Test project debug folder. This ensures that any assemblies can be resolved, as "unused" assemblies are not removed. You can add the following to your Test projects .csprog file:

<PropertyGroup>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
0

I solved my problem completely different to any of the solutions in here:

Each of my tests made a call to a function which in turn called itself meaning it'd not terminate:

public GoogleIntent CreateIntent(BotPath botpath)
{
    return CreateIntent(botpath);
}
Luke Garrigan
  • 4,571
  • 1
  • 21
  • 29
0

Upgrade your test project to the latest target framework version.

I was using Visual studio 2019 with target framework 4.5 whose support ended in 2016, jumping to 4.7 solved my problem.

Antoine L
  • 431
  • 4
  • 6
0

I had same issue after update to Visual Studio 16.4.1. Go to Test explorer -> Settings button -> Processor Architecture for AnyCPU projects -> x64

0

I had similar symptoms as OriolBG with the stack .Net Core/xUnit/FluentAssertions but for me updating the Microsoft.NET.Test.Sdk nuget package for the project did the trick.

Fabian
  • 1,100
  • 11
  • 14
0

I had the same issue, but mine was resolved when I created a working copy on my actual desktop. The issue for me was because of the project folder was located on a network drive, and the dependencies were not able to load across the network drive for some reason. Hope this helps someone.

EricHansen
  • 67
  • 8
0

Right click on the file in your solution explorer and make sure it's build action is set to "C# Compiler"

Solution Explorer --> Right Click File --> "Properties" --> Build Action = "C# Compiler"

enter image description here

Elliott
  • 2,035
  • 20
  • 23
0

Same issue. What was actually happening was that the test running was trying to discover tests in a web site project I have loaded (there was some jasmine specs for angular inside the site).

enter image description here

This was causing the runner to hang trying to load some NodeJS Container

Updating containers from Microsoft.NodejsTools.TestAdapter.TestContainer

enter image description here

I removed the website from the solution (obviously, just the solution, not deleting the website!)

I also had some corrupt configuration data that I had to clear out under the TestStore folder in the .vs directory.

Deleting the corrupted cache started the tests working again

After completing these two steps things magically started working again

Malcolm Swaine
  • 1,929
  • 24
  • 14
0

Yet another ridiculous case: it somehow happened that two projects in the same solution had the same ProjectId - one of those was a test project and that confused Test Runner.

Removing and readding test projects to the solution changed the ProjectId and fixed the issue.

psfinaki
  • 1,814
  • 15
  • 29
0

I was having this issue also and my solution was that I needed to make the test class "public". I created the test class via the Create Unit Tests Wizard through VS2019 and by default it doesn't make it public.

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

I also faced this issue when I used selenium NUnit test in Visual Studio 2019 Community version 16.9.1. Some of the suggestions was to use older versions. But in my case the actual solution was to add Microsoft.NET.Test.Sdk" Version="16.0.1" package to the project.

Packages included in my project

tgarcia
  • 675
  • 9
  • 21
0

I chose "Debug Selected Tests" in place of "Run Selected Tests" from test explorer.

RBT
  • 24,161
  • 21
  • 159
  • 240
0

Depending on the runtime installed, you may need to select:

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

Setting it as x64 caused a "The framework 'Microsoft.NETCore.App', version '3.1.0' was not found." error in the test error output.

Dean P
  • 1,841
  • 23
  • 23
0

This worked for me in VS2019.

Moved Tests to a new NUnit 3 Test Project. All tests ran as is.

gfoote
  • 11
  • 2
    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. – Chai May 24 '21 at 17:36
0

I had a similar problem, tried all posted solutions with no luck. After 2 days eventually figured out that it was OneDrive causing the problem.

Turned off OneDrive, waited a bit, restarted VS, and BAM, was working again!

Michael McQuirk
  • 113
  • 1
  • 7
0

Make sure you reference your test project with your main application project.

0

I had this issue, it turns out I left off "public" in front of the test class.

There is a warning for this under "Show output from: Tests"

"TestClass attribute defined on non-public class"
ORcoder
  • 252
  • 2
  • 11
0

Initially I created test project with .Net library and added xunit and xunit.runner.visualstudio, but that didn't help me to run test cases.

Later created test project with xunit test project template, which automatically added coverlet.collector, Microsoft.NET.Sdk, xunit, xunit.runner.visualstudio nuget packages. Now am able to run test cases.

Ram
  • 91
  • 4
0

Was facing this issue, my project is huge and have tons of test cases so I had to figure out this

I uncheked the option "Discover tests in real time from c# and visual basic .net source files"

its under Tools->Options->Test->General

enter image description here

Vivek Singh
  • 67
  • 1
  • 12
0

I had the same kind of problem in vs2022, but instead of getting blurred test results, the tests disappeared after running them. Also, no result was shown in the Test Explorer.

I could see that all tests worked in the Output window, but not on the Test Explorer Window where no test was shown.

In my case reinstalling vs2022 solved the problem.

Adrian
  • 1
  • 1
  • 2
    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. – Ruli Dec 11 '21 at 21:27
0

I found a test project ran fine in resharper but ran nothing in vs test. The solution was missing nuget package xunit.runner.visualstudio

I guess the test project was developed by someone with resharper, so they were never aware it did not run in visual studio test explorer.

andrew pate
  • 3,833
  • 36
  • 28
0

In my case needs to install Microsoft.NET.Test.Sdk

Dzmitriy Salodki
  • 93
  • 1
  • 2
  • 7
  • 2
    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. – Jeremy Caney Feb 27 '22 at 01:32
0

TLDR: Make sure all used projects are explicitly referenced

In my case I had a net461 unit test project that compiled fine and also ran fine when run from the Test Explorer explicitly.

When running 'all tests' or running 'not run tests', the test would stop halfway (when it got to the test in question).

Only output in test console:

========== Test run aborted: 270 Tests (270 Passed, 0 Failed, 0 Skipped) run in 5,1 sec ==========

When I converted the unit test project to netcoreapp3.1, the compiler complained about a missing project reference. It was referenced by another referenced project (hence implicitly available).

After the explicit project reference was added, I could revert back to net461, and all unit tests could be run from Test Explorer.

TheRoadrunner
  • 1,281
  • 14
  • 34
0

I was able to resolve the problem of non-running Testcases by removing (commenting out) the DeploymentItem attributes to the TestMethods. Environment:

  • VS2022
  • net462
  • MSTest.TestAdapter 2.2.8
  • MSTest.TestFramework 2.2.8
  • Microsoft.NET.Test.Sdk 16.11.0
Wolfgang Grinfeld
  • 870
  • 10
  • 11
0

For .net core project, adding the reference to the following fixed the issue of tests not running or getting greyed out.

MSTest.TestAdapter

0

I deleted the .vs folder and Test Explorer started working!

0

Following this article I found I had to add a reference and remove a package. I'm using vs 2022 but same goes for 2019. Found this page has the information to fix my issue. I found there are two ways to fix it.

I have framework 4.8 And reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework

The classes [TestClass] and [TestMethod] where visible because of a package installed, but adding that those attribute calsses where defined in the package and the added UnitTestFramework reference. Remove the package and showed it was ok running and debugging tests.

This is done another way by adding two packages. And you can add one package that will include the second.

Package Id's are: Microsoft.UnitTestFramework.Extensions MSTest.TestFramework

I believe the two package add is better than the one reference to assembly:

C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

0

I had the very same problem. A couple of questions first;

  • Do you use VS 2022?
  • Have you instsalled .net7 (preview) yet?
  • Do you use NUnit?

(This is at least what I have installed)

If so, then I might have found the solution. I came across this answer on GitHub: https://github.com/nunit/nunit3-vs-adapter/issues/987. I just updated my NUnit3TestAdapter NuGet package from version 4.2.1 to 4.3.0-alpha-net7.4, and now I can run all my tests again.

NuGet link: https://www.nuget.org/packages/NUnit3TestAdapter/4.3.0-alpha-net7.4

I found this error message in the Output tab > "Tests" in the dropdown, which helped me identify the issue:

No test is available in C:\xx\Tests\xx\bin\Debug\xx.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
NUnit Adapter 4.2.0.0: Test discovery starting
Exception System.TypeInitializationException, Exception thrown discovering tests in C:\xx\UnitTests\bin\Debug\UnitTests.dll
The type initializer for 'NUnit.Engine.Services.RuntimeFrameworkService' threw an exception.
   at NUnit.Engine.Services.RuntimeFrameworkService.ApplyImageData(TestPackage package)
   at NUnit.Engine.Services.RuntimeFrameworkService.SelectRuntimeFramework(TestPackage package)
   at NUnit.Engine.Runners.MasterTestRunner.GetEngineRunner()
   at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
   at NUnit.VisualStudio.TestAdapter.NUnitEngine.NUnitEngineAdapter.Explore(TestFilter filter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitEngine\NUnitEngineAdapter.cs:line 88
   at NUnit.VisualStudio.TestAdapter.NUnit3TestDiscoverer.DiscoverTests(IEnumerable`1 sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestDiscoverer.cs:line 82
InnerException: System.ArgumentException: Unknown framework version 7.0
Fred
  • 397
  • 2
  • 5
  • 17
0

I've read through all the answers. Here's my magic solution that worked for my case.

tl;dr: check for undetected errors in the test project

  1. Make sure the test files in your test projects have no build error by scrolling through them and looking for red squiggly lines. Visual studio was compiling fine without any error, but actually the test project could not compile.
    Note that also that _the Output log did not report anything. I repeat, no errors were reported in any place (neither in the Error tab, nor in the Output log set to Build or Test) although were actually present and discoverable by reading through the test files and looking for red squiggly lines.
    Note that the only project that had undiscovered errors was the test project.

  2. Once I had fixed the errors, Visual Studio still wouldn't run the tests. Remove the test project from the solution.

  3. Add a new dummy test project. Compile and run it. Verify that the empty test in the new test project run successfully.

  4. Add back the original test project (without removing the dummy). Run all tests. At this point, the original tests started running again for me.

My configuration
  • Visual Studio Community 2022
  • NUnit tests findable but would not run
  • My solution had a large MAUI Hybrid project, some independent class libraries in .NET7, and a single test project.
For the record, other solutions I tried and did not help
  • Check the Output Log for errors.
  • Check the compatiblity of all nuget packages and project with the .NET version.
  • Restart VS
  • Most of the other solutions proposed in this thread
alelom
  • 2,130
  • 3
  • 26
  • 38
0

I had this exact problem where I had 3 separate test projects, 2 of them ran without issue and the third one never ran, even if I tried to run the tests individually. There was no easy way to see what the reason was. The tests would not run on our YAML build pipeline in DevOps either.

Test project not running

Consolidate NuGet versions

First and foremost I would ensure your NuGet versions are consolidated for NUnit and NUnit3TestAdapter, to do this, right click the solution and click Manage NuGet packages for solution... go across to the Consolidate tab.

In my case the NuGet packages for NUnitTestAdapter were not aligned for the project that would not run, I consolidated those versions and then rebuilt the solution, ran all tests and now all 3 projects run successfully.

Check Output -> Tests

If the above doesn't work then I would suggest this step as it should output the exception being thrown by the test runner.

On the top bar select View and then Output (default shortcut Ctrl+Shift+U). Once this has opened change the drop-down for Show output from: to Tests, this should now give you the outputted logs from the test runner.

In my case the logs looked like this:

Multiple versions of same extension found. Selecting the highest version.
  NUnit3.TestAdapter : 4.3.0.0
Aborting test discovery because a test run was requested.
Discovery of tests cancelled.
The active test discovery was aborted.
========== Test discovery aborted: 0 Tests found in 3.9 sec ==========
Building Test Projects
Starting test discovery for requested test run
========== Starting test discovery ==========
Multiple versions of same extension found. Selecting the highest version.
  NUnit3.TestAdapter : 4.3.0.0
NUnit Adapter 4.3.0.0: Test discovery starting
Exception System.UnauthorizedAccessException, Exception thrown discovering tests in C:\Source\MainSolution\TestProject3.Tests\bin\Debug\net462\TestProject3.Tests.dll
Access to the path 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\InternalTrace.31504.log' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at NUnit.Engine.Internal.InternalTraceWriter..ctor(String logPath)
   at NUnit.Engine.Internal.InternalTrace.Initialize(String logName, InternalTraceLevel level)
   at NUnit.Engine.TestEngine.Initialize()
   at NUnit.Engine.TestEngine.GetRunner(TestPackage package)
   at NUnit.VisualStudio.TestAdapter.NUnit3TestDiscoverer.DiscoverTests(IEnumerable`1 sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestDiscoverer.cs:line 82
NUnit Adapter 4.3.0.0: Test discovery complete
No test is available in C:\Source\MainSolution\TestProject3.Tests\bin\Debug\net462\TestProject3.Tests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

The exception is being thrown by NUnit3TestDiscoverer.cs, at the start of the exception it mentions Multiple versions of same extension found. Selecting the highest version. NUnit3.TestAdapter : 4.3.0.0

There might be other exceptions being thrown in the logs, but in my case it was just the misalignment of NuGet versions.

Aaron P.
  • 188
  • 1
  • 11
0

In my case, it was because I didn't have a public, default constructor in the test class. I had created a default constructor with an internal access modifier.

rory.ap
  • 34,009
  • 10
  • 83
  • 174
0

All you need is to add this NUnit3TestAdapter nuget package to the project, then it will start picking up your tests

Distnie Manuel
  • 131
  • 1
  • 3
0

In my case it was because of wrong declaration of TestInitialize method. I had declared it as private static whereas it should be defined as public and non-static method as below:

[TestInitialize]
public void Initialize(){...}
Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
-5

Try removing the [Ignore] attribute from above the test method.

ross
  • 2,684
  • 2
  • 13
  • 22