Visual Studio 2013 doesn't discover unit tests
Solution 1
Some things I've noticed I have to do from time to time to get tests to show up properly.
If your solution is in a protected drive that you need administrator access to read/write, sometimes only a portion of the tests come up. Definitely run VS as administrator in that case.
If your solution is 64 bit, make sure that Test > Test Settings > Default Processor Architecture is set to x64. Sometimes it gets set to x86. Set it to x64, then rebuild.
Sometimes just restarting Visual Studio does the trick because the test explorer will start up again.
Don't forget to actually build the test project/solution. (If you want it to get built with the rest of the projects, right-click on your solution > Properties > Configuration Properties > Configuration > check the "Build" box for your test project)
Ensure the tests are in a
public
section of your test class
Solution 2
If you using NUnit, make sure to download NUnit Adapter first.
Go to Tools → Extensions and Updates… → Online → search for "NUnit Test Adapter".
Solution 3
Make sure your test class is public
so it can be found. And if you're referencing another class, make sure of the same.
Also, sometimes if you have no Asserts or you're not decorating the test with a [TestMethod]
, a test might not be recognized.
2 more things: 1) Async unit tests act funny at best, and none at all at worst. Have a look at this article by Stephen Cleary and keep from there if it interests you.
2) If you use NUnit and you run into the same issues, keep in mind it's [TestCase]
for Nunit, instead of [TestMethod]
Having said the above, here's an article I've posted on the code project, with both MSTest
& NUnit
, in case you want to give it a spin and make sure you're not missing anything.
Solution 4
I had the same issue but none of the other solutions worked. Turns out that I was using the NUnit 3 framework with the 2 adapter.
If you're using NUnit 3, go to Extensions and Updates and install the NUnit3 Test Adapter.
Solution 5
I'm having this issue from time to time. What works for me is to shutdown Visual Studio and go to folder:
%LocalAppData%\Microsoft\VisualStudio\12.0\ComponentModelCache
and delete it content.
Once you open Visual Studio and load your project again Test Explorer should contain back your tests
Related videos on Youtube
miguelbgouveia
I am developer with 10 years of experience. Interested in open source and sharing ideas. Coding using TDD process.
Updated on February 08, 2021Comments
-
miguelbgouveia about 3 years
I have a simple solution in visual studio 2013 that is composed by one web project, one library project and one unit test project. When I open the solution and try to run the unit tests they are not discover by visual studio. To run the tests I try to go to the menu and choose Test -> Run -> Run all tests or by opening the test explorer window. By those to methods visual studio doesn’t discover any tests in the solution.
Creating first a simple unit tests project and try to run the test, visual studio know discover the test and I can run it. Then, if I open my previous solution visual studio now discovers all the tests. I try to save my solution but closing it and reopening, without creating a unit test project first, the visual studio doesn’t find the tests again. This is a very strange behave that I don’t know why this is happening.
I used to working alone in this project that was using the source control git integrated with the visual studio team foundation. The problem of visual studio not discover the unit tests start when a new element came to the project and when I need to recreate the solution through the source control online. Before this, all tests always been discovered by visual studio.
For creation the unit tests I use the dll Microsoft.VisualStudio.QualityTools.UnitTestFramework. My version of visual studio is: Microsoft Visual Studio Express 2013 for Web Version 12.0.30723.00 Update 3. My version of .net framework is 4.5.50938.
All of my tests are like this:
[TestClass] public class Service1Test { [TestMethod] public void Test1() { Assert.IsTrue(True); } }
-
Jamie Keeling over 9 yearsAre these Async based Unit tests?
-
Sriram Sakthivel over 9 yearsNot sure what the issue was, but running as administrator fixed the issue for me.
-
miguelbgouveia over 9 yearsAll sync based unit tests
-
Random Dev over 9 yearsHave you tried an external test-runner (like ReSharpers or NCrunch)? Maybe your install is bugged (so reinstall VS)
-
miguelbgouveia over 9 yearsI already try to reinstall visual studio and make all the updates but the problem maintains. I will try an external tool but I think it will work fine. The problem seems to be in visual studio.
-
Jeroen Vannevel over 9 yearsDid you clean your solution and rebuild everything? Perhaps rebuild all projects inside it separately? Do you get any output in the Tests and Build output pane?
-
miguelbgouveia over 9 yearsI try to install the external tool NCrunch. I think because I’m using VSExpress version I have to install this tool manually. After I run the command: VWDExpress.exe /setup /nosetupvstemplates to install the tool miraculously the tests start appearing in VS. Closing a reopening the solution, the tests disappear again. Funny that after all the installation of the tool doesn’t result.
-
miguelbgouveia over 9 years@JeroenVannevel, I already try to clean my solution and rebuild everything without results. Rebuild all projects also doesn’t work. When building the projects I get the following message: ------ Discover test started ------ The system cannot find the file specified ========== Discover test finished: 0 found (0:00:00,2675781) ==========
-
Adam over 7 yearsNone of these fixed the issue for me :( What a disaster. I've given up NUnit and am relying on UnitTestFramework - bizarrely the opposite problem from the OP
-
miguelbgouveia over 7 yearsThe same for me @Adam. I use known Xunit.
-
Ruben about 7 yearsfor me it was not working because my project was located on a network drive, moving it to a local folder fixed it
-
-
miguelbgouveia over 9 yearsAll of my tests are like this: [TestClass] public class ServicesUtilsTest { [TestMethod] public void Test1() { Assert.IsTrue(True); } }
-
Noctis over 9 yearsthis is not very clear . Put it in a code block in your question, so it can be understood :)
-
miguelbgouveia over 9 yearsAll my tests is for sync code, and I think my problem is not in the unit tests code but more in visual studio sometimes not discovering the tests.
-
Noctis over 9 yearsTry using this instead:
using Microsoft.VisualStudio.TestTools.UnitTesting;
-
miguelbgouveia over 9 yearsI am already using Microsoft.VisualStudio.TestTools.UnitTesting. This namespace are defined in the dll Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
-
Jeroen Vannevel over 9 yearsAsynchronous unit tests are supported in VS 2013, which is what the OP is using.
-
Noctis over 9 years@JeroenVannevel Yep, but they might not act as he expects, unless he's aware of what's happening.
-
AndyG about 9 yearsI realize this answer is a little late, but my Google search brought me here, and nothing mentioned solved my problem. Eventually I figured out it was #2 in my list, so I wanted to leave that knowledge, plus the other tricks I've picked up over time.
-
miguelbgouveia almost 9 yearsI'm using UnitTests from Microsoft. In this case I suppose that isn't necessary install anything.
-
Nate Barbettini almost 9 yearsA combination of #2 and #3 did it for me. Visual Studio complained about a number of (non-test) projects in my solution being excluded from the test discovery step because they were built for x86, but that was fine.
-
user1807768 almost 9 yearsI found that my settings were all correct and restarting did not work. What did fix the problem for me was simply building the solution. I know this may seem dumb but it is not obvious that is necessary; I have not seen any of the official docs mention this step.
-
Frank almost 9 yearsIt does say this in the description of the Nuget package. But if you're like me and don't read, I'm hoping that this will help: "This package includes the NUnit 3.0 framework assembly, which is referenced by your tests. You will need to install version 3.0 of the nunit-console program or a third-party runner that supports NUnit 3.0 in order to execute tests. Runners intended for use with NUnit 2.x will not run 3.0 tests correctly."
-
miguelbgouveia almost 9 yearsBut where is the solutions platform menu? Is that in Visual Studio? I'm using Visual Studio Express 2013 for Web and I can't find that menu.
-
miguelbgouveia almost 9 yearsFor me that doesn't work. I am using Visual Studio 2013 Express with update 5 install recently. Still no unit tests appearing.
-
miguelbgouveia over 8 yearsI don't have any Configuration Manager option in my project menu. I can only find the project properties option. I very the platform of the unit tests project and it is the same of the others projects. So, for me this solution doesn't work.
-
miguelbgouveia over 8 yearsFor me, the dll's for the tests also weren't build because visual studio doesn't find any defined tests. I'm using Visual Studio Express and I don't have the Build menu entry. But in my configuration manager I have all build options checked. So, I think that is no the problem for my case.
-
mcolegro over 8 yearsI had the same problem in VS2015. #2 fixed the problem for me.
-
Rich Shealer over 8 yearsIn my case I knew it had something to do with the NUnit3 update, but one set of my test passed and the others weren't seen. Upon closer inspection there were a lot of exceptions in the output, even though the tests all passed.
-
amalgamate over 8 yearsDefine "matches the rest of the project"
-
Matas Vaitkevicius over 8 yearsThis did it for me - much obliged.
-
Eduardo Brites over 8 yearsI just had to build the Test project using Any CPU, the other projects remained x64
-
Jens over 8 yearsThis was the case for me too. I had run nuget "update-package" without realizing it updated from NUnit 2.x to 3.x.
-
Matthew Hoggan over 8 yearsI have no idea why people pay so much money for a product that fails so often. I had to upgrade my project to 2015 and do #3 2 times before it discovered my test.
-
Chris Hawkes over 8 yearsI hate the test explorer with a passion
-
miguelbgouveia over 8 yearsI known that using another unit test framework will resolve my problem. But if I wanted continuing use the Microsoft Unit Tests framework that is not a solution.
-
miguelbgouveia about 8 yearsI'm using UnitTests from Microsoft. In this case I suppose that isn't necessary install anything.
-
Admin about 8 years@miguelbgouveia, it's the other way around - VS builds DLLs, and then scans those for tests. So if you have no test project DLLs, you will definetely find no tests.
-
miguelbgouveia about 8 yearsThat already happen to me. But in this they that is not the case.
-
miguelbgouveia about 8 yearsMy classes are not abstract. That's not my problem.
-
vauhochzett about 8 yearsCurrently the NUnit 3.0 Test Adapter can't be found via NuGet (see the NUnit 3.0 Wiki). It can stil be installed as an extension though.
-
miguelbgouveia about 8 yearsI am not using NUnit.
-
Ryan Buddicom about 8 years#4 for me, had forgotten that I had set the test project to only build in debug.
-
FuckStackoverflow about 8 yearsOf all the things.... This was my problem and the params bit makes sense. After all, what would the test system know to pass in? The solution there is to make a test method where you manually call the method you want to test. If you're testing a WebAPI project and have a Get with params, you still have to have the matching Get call but it won't show up in explorer.
-
metalhead about 8 years5. Make sure your assembly isn't also in the GAC. The test explorer will find the one in the GAC first and not see your new tests in your solution.
-
Jonathan Gilbert almost 8 yearsTechnically, C#/VB.NET always compile to MSIL. The project setting "x86", "x64" or "Any CPU" (and, in newer versions, "Prefer 32-bit") is just flags at the top of the EXE/DLL. Point still stands, though; NUnit won't list tests it can't load into the execution engine, on account of them being marked as requiring a particular architecture to run.
-
tyrion almost 8 yearsI had a NUnit 2 Test Adapter installed with NUnit 3 framework as nuget package. Reading your answer made me realize this mistake. After installing Nunit 3 Test Adapter, it works fine for me. Thanks for the hint.
-
santosh kumar patro almost 8 yearsThanks a lot Frank. It solved my issue. Now I am able to see the unit test results in the console window :)
-
Jacob McKay almost 8 yearsHmmm I had private fields in my test class, and when I switched em to public after reading this my test was rediscovered. Thanks @Noctis
-
Siva Sankar Gorantla almost 8 yearsIn my case, class was not public.. Thank you
-
C-F almost 8 yearsThis does not answer the question above, but this is exactly the problem I was trying to solve. So you got accident +1 :) Thank you so much!
-
escape-llc over 7 yearsgot me too! i forgot to make the test context property
public
. -
duyn9uyen over 7 yearsI had to switch my solution configuration to Debug. It was on one of my other transform configs.
-
AndyG over 7 years@duyn9uyen: That's interesting, is there are preprocessor macro that prevents the tests from compiling unless it's for DEBUG?
-
Sipke Schoorstra over 7 yearsNumber 2 + 3 did the trick for me. I was experiencing this issue in VS 2015, where my solution contains Service Fabric projects (x64), but my unit test class libraries were set to "Any CPU". So as soon as I referenced an x64 project from the unit test project, the tests would simply fail to be discovered. So in addition to #2 and #3, I had to change the target platform of the unit test project to x64.
-
MartijnK over 7 yearsIt's in the solution of your project. Right-click your project file in the Solution Explorer -> Open Folder in File Explorer. Go one directory up from there and delete the /TestResults directory. You may have to shut down Visual Studio to delete everything. It will rebuild the directory the next time the project is opened.
-
Vort3x over 7 yearsSame problem with VS2015 Community edtion. I actually had this issue after the Windows 10 Anniversary update, I needed to run as administrator (previously this wasn't necessary). So #1 for me. Thanks for the thorough answer @AndyG
-
amarnath chatterjee over 7 yearsI was facing the same issue , had a hard time in finding which dlls were not loading....
-
causa prima over 7 years#3 was my problem. Thanks.
-
Tom over 7 yearsTo elaborate on step #1: I had NUnit installed but it was for unknown reasons disabled. Uninstalling didn't seem possible and then it hit me: I've been running VS with Administrator privileges whilst NUnit was installed without it.
-
some bits flipped over 7 years@metalhead - I did not need to check the GAC, but if you're right about that please edit the answer to add it. And man, i'll add, that's insane. How this (relatively expensive) product can fail silently like this, requiring (for me) some arbitrary combination of #2 and a vs-restart (#3) ...
-
Aaron over 7 yearsThis triggered the solution for me; the test function was marked
static
. Removing the modifier and rebuilding the project immediately made it appear in the Test Explorer. -
Noctis over 7 years@Aaron hmm ... interesting ...wonder why a static method will not be picked up ... you using mstest or nunit? and which version btw ?
-
Aaron over 7 years@Noctis MSTest,
"MSTest.TestAdapter" version="1.1.8-rc"
and"MSTest.TestFramework" version="1.0.8-rc"
. -
Stephan Møller over 7 yearsThis was also what worker for me. Even worked without restarting visual studio. Hours down the drain finally had an end.
-
jjthebig1 about 7 yearsThat fixed it for me. Thanks.
-
jao about 7 yearsDon't forget to make the test method public. Took me a good part of an hour to figure that out!
-
Owain Glyndŵr about 7 yearsUpvoted as did resolve issue but is it necessary to have NUnit adapter or should Visual Stdio work with NUnit out-the-box.
-
whiteshooz about 7 yearsAdding the following dependency fixed it for me:
"Microsoft.DotNet.InternalAbstractions": "1.0.1-beta-003206"
-
Nox about 7 yearsYou are a god sir.
-
Skystrider over 6 yearsThis didn't work for me. Test explorer just does not find my test and as far as I can tell I'm not doing it wrong and I've tried some of the solutions here without success.
-
Noel Widmer over 6 yearsThis directory does no longer exist in VS2017.
-
Nathan over 5 yearsUsing MsTestV2 - this was the only thing that fixed the problem
-
Ravi Kumar Mistry about 4 yearsThanks it works for me for any of those this folder can have diffrent version depending on the installation of visual studio like for me it is
%LocalAppData%\Microsoft\VisualStudio\16.0_03b7a93c\ComponentModelCache