224

I have some tests that use the built in Microsoft.VisualStudio.TestTools.UnitTesting, but can not get them to run.

I am using visual studio 2012 ultimate.

I have a solution of two projects; One has tests, using Microsoft.VisualStudio.TestTools.UnitTesting, [TestClass] before the class, [TestMethod] before the test methods and reference Microsoft.VisualStudio.QualityTools.UnitTestFramework (version 10.0.0.0, runtime version v2.0.50727). I have tried dot-net framework 3.5, 4 and 4.5 others give a re-targeting error.

I have tried to build the solution and project. Test explorer has the message `Build your solution to discover all available tests. Click "run all" to build, discover, and run all tests in your solution.

So the question is: How to I get visual studio to find the tests?


Have also tried to follow this: http://msdn.microsoft.com/en-US/library/ms379625%28v=VS.80%29.aspx but with no success: I get stuck in section getting started, when asked to right click and select create tests. There is no create tests.


I have this test(it compiles, but does not show up in test explorer):

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace tests {
    [TestClass]
    public class SimpleTest {
        [TestMethod]
        public void Test() {
            Assert.AreEqual("a","a", "same");
        }
    }
}

I have now discovered (see deleted answer below) that it is because it is on a shared drive, but I don't as yet know how to get around it. (something about the security setting maybe).

Gray
  • 27
  • 7
ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
  • Which version VS 2012? You could download a test runner like TestDriven.Net or there is one in Resharper. – Brett Allred Nov 23 '12 at 17:33
  • I am using visual studio 2012 ultimate. – ctrl-alt-delor Nov 23 '12 at 17:39
  • Please share framework version and UnitTesting library version you have added as reference – Adil Nov 25 '12 at 08:07
  • This should work out of the box. Please submit this at http://connect.microsoft.com/visualstudio with your code. – Oleg Sych Nov 26 '12 at 17:14
  • 5
    In my case removing the app.config file fixed the unit test explorer – Chris Richner Jun 04 '13 at 06:06
  • I have fixed this by giving full trust to the network share using `caspol` tool. Please see my answer below. – Taras Alenin Aug 08 '13 at 04:44
  • @Chris Richner this fixed my problem, but it was because I previously had a binding redirect in the App.config (I just did an upgrade from VS2010 -> VS2013 then down to VS2012) – mejdev Aug 13 '13 at 16:20
  • 4
    Try looking for errors under 'Test' category in output window. I create functional tests from release build and when I try to debug using debug build (whose dlls are located in a different folder structure), I dont get any build errors but have to look under tests from the pull down menu. Once I resolve those, tests start to appear in the Test Explorer – gDexter42 Mar 21 '14 at 23:17
  • My issue was even simpler: My class wasn't public. (Hope that helps someone else hit their doh! moment quicker..) – Gene Jul 22 '15 at 20:04
  • Just rebuilding the test project did it for me. – live-love Oct 07 '15 at 15:21
  • I was retarded enough to forget that I had selected a test playlist. – Mateen Ulhaq Feb 29 '16 at 21:09

49 Answers49

228

I had same symptoms, but under different circumstances.

I had to add one additional step to Peter Lamberg's solution — Clean your solution/project.

My unittest project targets x64. When I created the project it was originally targeting x86.

After switching to x64 all my unit tests disappeared.

I had to go to the Test Menu -> Test Setting -Default Processor Architecture -> x64.

They still didn't show up.

Did a build.

Still didn't show up.

Finally did a Clean

Then they showed up.

I find Clean Solution and Clean to be quite useful at getting the solutions to play ball when setting have changed. Sometimes I have to go to the extreme and delete the obj and bin directories and do a rebuild.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
Ourjamie
  • 2,439
  • 1
  • 14
  • 10
  • While doing a clean does sometimes help, it is not the issue. I have a problem with projects on network drives. And the fact that build helps ever is just a symptom of a buggy build tool. – ctrl-alt-delor Aug 11 '13 at 20:23
  • 7
    Wow! The "Clean Solution" really seems to work (as opposed to just a rebuild all). I thought this stopped being a useful hack back in Visual Studio 6.0! – Dave Jan 02 '14 at 23:54
  • "Clean" didn't work for my coworker who had this issue. It worked for her after deleting all the source code from her TFS workspace, and getting latest (w/ overwrite). Then it worked great! – Michael R Feb 19 '14 at 22:11
  • 2
    This was it for me. In a solution with mix of x86, Any CPU, x64, one particular project's tests weren't being found. I cleaned the solution, changed the test setting's default architecture, and rebuilt and then everything could be seen. It really makes no sense, since changing the architecture discovered tests compiled under a different CPU architecture. – Ben H Apr 22 '14 at 18:17
  • I have done all of your steps + (put all my project dll to GAC then it works calm.)Thank you sir. – Prageeth godage Aug 22 '14 at 03:56
  • I had to follow these steps, switch from x86 to x64, follow these steps, and switch back again and then it worked for me. (Oddly this was in VS 2013 and my side by side install of VS 2012 had no problems at any point...) – John Reilly Oct 29 '14 at 11:52
  • 2
    Right when I changed default processor -- all my tests showed. Thanks so much for this! – Dan But Mar 13 '15 at 02:07
  • As of VS2013 this still happens from time to time, some things with Microsoft never change. – Chris Hawkes Nov 09 '15 at 19:29
161

Please add the keyword public to your class definition. Your test class is currently not visible outside its own assembly.

namespace tests {
    [TestClass]
    public class SimpleTest {
        [TestMethod]
        public void Test() {
            Assert.AreEqual("a","a", "same");
        }
    }
}
Joseph King
  • 5,089
  • 1
  • 30
  • 37
58

This sometimes works.

Check that the processor architecture under Test menu matches the one you use to build the solution.

Test -> Test Settings -> Default Processor Architecture -> x86 / x64

As mentioned in other posts, make sure you have the Test Explorer window open. Test -> Windows -> Test Explorer

Then rebuilding the project with the tests should make the tests appear in Test Explorer.

Edit: As Ourjamie pointed out below, doing a clean build may also help. In addition to that, here is one more thing I encountered:

The "Build" checkbox was unticked in Configuration Manager for a new test project I had created under the solution.

Go to Build -> Configuration Manager. Make sure your test project has build checkbox checked for all solution configurations and solution platforms.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69
  • Yes these may be other reasons that it will not work, but see ticked answer below for why it did not work for me. (shared folders are disabled by default), if you can tell us how to change this I will give you some points. – ctrl-alt-delor Mar 21 '13 at 10:10
  • There is no such processor as an x64, but I thing microsoft uses this term for the x86-64/amd64/x86e. There is also no x86, just the x86 family. The x stands for the unknown, so the members of the x64 family would be 164, 264, 364 … OR was the x86 an 86 bit processor. – ctrl-alt-delor Mar 21 '13 at 10:13
  • thanks for your answer, it helps me (I switched from x86 builds to x64 builds) – enguerran Mar 28 '13 at 13:42
  • Even in VS 2015 having the Test Explorer window open worked. Glad that I can also run tests from the command line. – Bryan Jan 20 '16 at 21:19
32

I have Visual Studio 2012 and i couldn't see the Tests in Test Explorer,

So I installed the following: NUnit Test Adapter

That fixed the issue for me !

dnnyz
  • 386
  • 3
  • 4
  • 1
    Also available via NuGet `Install-Package NUnitTestAdapter` – DJH Jan 15 '15 at 14:05
  • 1
    Thanks @DarrenHale. While searching for this package in NuGet, I also found a bundle called _NUnit TestAdapter including NUnit 2.6.4 Framework_. – ray Jul 08 '15 at 16:26
18

In my recent experience all of the above did not work. My test method

public async void ListCaseReplace() { ... }

was not showing up but compiling fine. When I removed the async keyword the test the showed up in the Test Explorer. This is bacause async void is a 'fire-and-forget' method. Make the method async Task and you will get your test back!

In addition, not having the Test project's configuration set to "Build" will also prevent tests from showing up. Configuration Manager > Check your Test to build.

MoonKnight
  • 23,214
  • 40
  • 145
  • 277
  • 2
    It took me a good while to figure this out. I refactored a few methods to be async and just added the keyword to the tests. It was only when I coded a new unit test with this that I noticed the other tests were also missing. I found [this answer](http://stackoverflow.com/questions/19317135/why-cant-async-void-unit-tests-be-recognized) which explains why this happens. – julealgon Jun 10 '14 at 15:43
12

Since the project is on a shared drive as the original poster have indicated. VS.NET needs to trust network location before it will load and run your test assemblies. Have a read of this blog post.

To allow VS.NET to load things of a network share one needs to add them (shares) to trusted locations. To add a location to a full trust list run (obviously amend as required for you environment):

 caspol -m -ag 1.2 -url file:///H:/* FullTrust

To verify or list existing trusted locations run:

 caspol -lg
Taras Alenin
  • 8,094
  • 4
  • 40
  • 32
  • This answer is unverified by questioner, as I no longer have an interest in the answer. If it works for you (or not), then add a comment below. – ctrl-alt-delor Aug 11 '13 at 20:18
  • 6
    @richard So you accept an answer you didn't verify and downvote other answers that describe solutions for different causes of your problem? ....That's weird! – Stephan Bauer Aug 12 '13 at 06:36
  • 1
    This turned out to be the problem for me, but not the solution. I moved everything local and all the tests were found! Thanks! – Travis Swientek Sep 10 '13 at 21:59
  • 1
    `CasPol.exe` can be found under `%windir%\Microsoft.NET\Framework[64]\[version]`. Verify that you are setting the policy for the proper architecture. Source: http://msdn.microsoft.com/en-us/library/cb6t8dtz%28v=vs.100%29.aspx – EpicVoyage Nov 03 '14 at 06:09
  • This was also the problem for me. So annoying that VS didn't pick them up but gave zero indication as to the cause! – kaybee99 Jan 28 '15 at 16:22
10

A problem I've found is that tests don't get found in the Test Explorer (nothing shows up) if the solution is running off a network drive / network location / shared drive

You can fix this by adding an environment variable.

COMPLUS_LoadFromRemoteSources and set its value to 1

tim
  • 101
  • 1
  • 2
6

I was getting the error: "Failed to initialize client proxy: could not connect to vstest.discoveryengine.exe."

Try to run Visual Studio as Administrator. That worked for me.

There is another Stack Overflow post discussing this error, and the same solution works for them. The question remains why this works.

Community
  • 1
  • 1
Edward Olamisan
  • 800
  • 1
  • 18
  • 28
  • 3
    Worked for me too! I think this is a separate issue. – Justin Morgan - On strike May 16 '13 at 15:06
  • 2
    Hey this works man. Thank you very much.. Any workaround to make it work without running as administrator? – Sriram Sakthivel Dec 02 '13 at 06:43
  • 2
    Sorry I don't think that running as admin is a good solution. Unless evidence that this is the only way. – ctrl-alt-delor Jan 24 '14 at 10:08
  • Running as admin is usually not a big problem. But one of the issues is that you cannot send the Workitem to outlook. – Edward Olamisan Jan 24 '14 at 13:42
  • Edited your answer to link to a related SO post, hope you don't mind. I agree with Sriram and richard though. Although this works, it is a workaround, not a solution. Why it even works at all seems unclear. – Steven Jeuris Dec 21 '14 at 22:29
  • @EdwardOlamisan The reason that running as admin is not a good idea, is that it will make your system more vulnerable ( a bug in your code could destroy the OS ). If you are running Microsoft's Windows, then you may not think that this matters. – ctrl-alt-delor Dec 22 '15 at 23:07
6

I had the same problem.. In my case it was caused by a private property TestContext.

Changing it to the following helped:

public TestContext TestContext
{
    get;
    set;
}

After cleaning and building the solution (as described in @Ourjamie 's answer), the test methods in the affected test class were available in the Test Explorer.

Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
  • OK same symptoms, so will remove down-vote, if you make clear what you changed (from what). – ctrl-alt-delor Jan 24 '14 at 10:18
  • 1
    I had exactly the same, I followed the complete thread, then came to this one and brought me to the idea to set it to public , bingo: my new tests appeared. I understand previous comments but ... since this one brings us from Google... this is the thread to read when tests do not show up. – edelwater Sep 01 '14 at 19:55
  • 1
    This was the cause of my problem. I had a field for the dependency interface as a private field. You are a life saver! – Alex Dec 18 '15 at 13:27
6

I ran into the same issue while trying to open the solution on a network share. No unit test would be detected by Test Explorer in this case. The solution turns out to be:

Control Panel -> Internet Options -> "Security" Tab -> Click "Intranet" and add the server IP address or host name holding the network share to the "Sites" list.

After doing this, I recompiled the solution and now tests appeared. This should be quite similar to the answer made by @BigT.

dracocephalum
  • 61
  • 2
  • 2
6

Quick check list for solving some common test problems. Make sure that:

  1. Test class and test methods are public
  2. Test class has [TestClass] attribute
  3. Test methods have [TestMethod] attribute

If this does not help, try cleaning, rebuilding solution and restarting Visual Studio.

SoftwareFactor
  • 8,430
  • 3
  • 30
  • 34
4

I sometimes get the same symptoms.

What I did is:
1. Closed the Test Explorer window
2. Cleaned the solution
3. Rebuild the solution
4. Relaunched Test Explorer window from Test -> Windows -> Test Explorer.

And I got my test in Test Explorer window.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
CSharp
  • 1,573
  • 2
  • 14
  • 25
2

From menu bar on top...

Test -> Run -> All Tests

You may also view all tests from Test Explorer (Test -> Windows -> Test Explorer)

Further with VS 2012, if you miss out anything try searching it using Quick Launch bar on top right (Ctrl + Q) "Test"

Hope this helps.

Adil
  • 3,248
  • 1
  • 22
  • 27
  • I tried that, both work with nunit. But this time I am trying to run someone else’s tests written using `Microsoft.VisualStudio.TestTools.UnitTesting`, any idea what else I am doing wrong? – ctrl-alt-delor Nov 23 '12 at 17:36
  • Doesn't make any difference... At times it happens not to discover unit test... so if u open test explorer and build solution, it will bring up unit test in a while... May be u already know that... – Adil Nov 23 '12 at 17:40
  • 2
    I just wanted to make sure you were using an express version or one that didn't include test tools. Have you tried installing a third party test runner? – Brett Allred Nov 24 '12 at 14:34
2

I found the best way to troubleshoot this issue is to create a .proj msbuild file and add your unit test projects which you hare having an issue into this file and execute the tests using the command line version of mstest. I found a small configuration issue in my app.config which only appeared when running the tests from mstest - otherwise the test project built just fine. Also you will find any indirect reference issues with this method as well. Once you can run the Unit test from the command line using mstest you can then do a clean solution, rebuild solution and your test should be discovered properly.

Todd Carter
  • 879
  • 7
  • 20
  • in my case the app.config also killed the appearance of the unit test. After deleting the app.config and rebuilding the test project they were finally back! – Chris Richner Jun 04 '13 at 05:53
2

In My case it was something else. I had installed a package and then uninstall it and reinstall an earlier version. That left a residual configuration/runtime/asssemblyBinding/dependencyIdentity redirecting in my app.config. I had to correct it. I figured it out by looking at the Output window and selecting "Tests" in the drop down. The error message was there. This was a pain... I hope it helps someone else.

Nestor
  • 13,706
  • 11
  • 78
  • 119
2

This is more to help people who end up here rather than answer the OP's question:

Try closing and re-opening visual studio, did the trick for me.

Hope this helps someone.

Jake_Howard
  • 2,533
  • 2
  • 15
  • 13
2

I know this is an older question but with Visual Studio 2015 I was having issues where my newly created test class was not being recognized. Tried everything. What ended up being the issue was that the class was not "included in the project". I only found this on restarting Visual Studio and noticing that my test class was not there. Upon showing hidden files, I saw it, as well as other classes I had written, were not included. Hope that helps

mortey
  • 179
  • 1
  • 4
  • 15
2

I was experiencing this issue many times when I try to build the solution in a different PC.

I am using NUnit and Specflow as well. By default My test project targets X86 But I have to change this to X64. Steps are 1. Test Menu -> Test Setting -Default Processor Architecture -> x64. 2. Clean Build 3. Build 4. If still tests didn't show up. 5. Go to Tools  Extensions and Updates Then Install NUnit and Specflow libraries 6. Clean Build 7. Build

Then usually test will showed up in Test Editor.

  • @srebella Good that you resolved this issue. I spent days to resolve this. Pls share your experience with community. Please put this answer to top if you believe it works. Thanks :-) – Shiran Jayawardena Mar 28 '17 at 15:32
1

I've updated VS 2012 to the Latest Update . ie visual studio update 3. That fixed the issue for me.

sam
  • 320
  • 3
  • 14
1

For Me the solution was just a little bit less complicated.

I had just brought an existing solution on to my machine (cloned from gitHub) and we do not track the auto-generated .cs files that Visual Studio created. (For each feature file there is a .cs file with the same name)

Opening the solution without having the associated .cs files actually allow me to navigate to the bound methods, so it appeared as if specflow was wired up properly, but I was not able to view the test names in the Test Explorer.

For this problem simply excluding the feature files from the project and then re-including them, forced VS to regenerate these auto generated codebehind files.

After that, I was able to view the tests in the test explorer.

Zack Weiner
  • 664
  • 4
  • 14
1

I had this problem when upgrading my solution from Microsoft Visual Studio 2012 Express for Web to Microsoft Visual Studio 2013.

I had created a Unit Tests project in 2012, and after opening in 2013 the Unit Test project wouldn't show any tests in the tests explorer. Everytime I tried to run or debug tests it failed, saying the following in the output window:

    Failed to initialize client proxy: 
    could not connect to vstest.discoveryengine.x86.exe

I also noticed that on debugging the tests, it was launching an instance of Visual Studio 2012. This clued me into the fact that the Unit Tests project was still referencing 2012. Looking at the test project reference I realised it was targeting the wrong Microsoft Visual Studio Unit Test Framework DLL for this version of Visual Studio:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

I changed the version number from 11.0 to 12.0:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

I rebuilt all and this fixed the issue - all tests were found in the Test Explorer and now all tests are found and running perfectly.

ladygargar
  • 597
  • 10
  • 14
1

Check that your test project is not set to Delay sign only in your project properties -> Signing. If it is, deselect it and do a clean rebuild.

Jan Dolejsi
  • 1,389
  • 13
  • 25
  • or just skip the signature check on your local machine by `sn -Vr *,` as adminstrator in VS developer command prompt – Silas Feb 24 '15 at 11:02
1

I hit the same problem while trying to open the solution on a network share in VS2013 Ultimate.

I corrected the problem by turning on

Control Panel -> Internet Options -> "Security" Tab -> Click "Local intranet", click on sites and make sure "Automatically detect intranet network" is ticked.

huddy72
  • 11
  • 2
1

These are all great answers, but there is one more reason that I know of; I just ran into it. In one of my tests I had a ReSharper message indicating that I had an unused private class. It was a class I'm going to use in an upcoming test. This actually caused all of my tests to disappear.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
1

Check referenced assemblies for any assemblies that may have "Copy Local" set to "False".

If your test project builds to it's own folder (bin/Debug for example) and the project depends on another assembly and one of those assemblies in the References list is marked Copy Local = "False", the assembly cannot load due to missing dependencies and your tests will not load after a build.

Joshua Starner
  • 1,573
  • 1
  • 13
  • 13
1

None of the solutions here helped me. The tests wouldn't be discovered for one solution whereas another solution referencing the same projects worked fine. I finally solved this by deleting the solutionname.v12.suo file.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
Craig Fisher
  • 1,681
  • 2
  • 19
  • 26
1

It looks like NUnit Framework 2.6.4 does not work well with NUnit Test Adapter. In the website it mentions the test adapter will only work with NUnit Framework 2.6.3.

This was my problem: 1. I had downloaded NUnit and NUnit Test Adapter separately through Nuget in the VS2012. Somehow NUnit got updated to 2.6.4 Suddenly i did not see my test cases listed.

Fix:

  1. Uninstall Nuget and Nuget Test adapter

    a. Go to Tools> Nuget > Nuget Pkg manager > Manage Nuget Pkg for Solution

    b. List installed packages

    c. Click manage

    d. Un-check your projects

  2. Install NUnit Test Adapter including NUnit 2.6.3 Framework

  3. Clean/Rebuild solution

  4. Open Test > Test Explorer > Run All

I see all the test cases

Hope this helps

user2831855
  • 189
  • 1
  • 6
1

I had same issue, but a bit different.

I was using visual studio 2012. For some reason, only the tests of the initial generated file was running. But tests in another file were not running. Tried out different solutions posted here, did not work.

Finally I figured out that I had a private method in the test class which was the first method inside the class. I just moved the private method after a test method; so now, a method with [TestMethod] attribute is the first method inside the class. Strange, but now it works.

Hope this helps someone someday.

mshsayem
  • 17,557
  • 11
  • 61
  • 69
1

Tests do not like async methods. Eg:

    [TestMethod]
    public async void TestMethod1()
    {
        TestLib oLib = new TestLib();
        var bTest = await oLib.Authenticate();

    }

After doing this:

    [TestMethod]
    public void TestAuth()
    {
        TestMethod1();
    }

    public async void TestMethod1()
    {
        TestLib oLib = new TestLib();
        var bTest = await oLib.Authenticate();

    }

It saw the test.

Zonus
  • 2,313
  • 2
  • 26
  • 48
  • A better answer is `[Test] public void XamarinExampleTest() { // This workaround is necessary on Xamarin, // which doesn't support async unit test methods. Task.Run(async () => { // Actual test code here. }).GetAwaiter().GetResult(); }` – Robert Green MBA Feb 26 '17 at 20:09
  • 3
    _"Tests do not like **async** methods"_ is **false**. _"Tests do not like **async void** methods"_ is **true**, and the solution is simply to declare a test method as **async Task**. – Massimiliano Kraus Apr 26 '17 at 18:18
1

Adding my answer as this is the top result on Google for this.

I'm using Visual Studio 2015 and (unknowingly - I just ran Install-Package NUnit) installed the NUnit3 package NuGet to my test project. I already had the NUnit Test Adapter extension installed, and my tests were still not showing up.

Installing the NUnit3 Test Adapter through Tools > Extensions and Updates fixed this for me.

Simon
  • 2,810
  • 2
  • 18
  • 23
0

I tried all the above and still my Visual Studio 2012 did not show up the tests. In the end I went to a test class and found it had a RootNamespace.FolderName and I removed the .FolderName to put the class in the root namespace and bingo all the tests came back!

Cannot understand why it was working fine with the original namespace till the other day.

David K
  • 11
0

I copy-pasted the method declaration, which included an input string parameter. Forgot to delete the input parameter.

  public void ExtractValueFromLineTest(string input) {}//test not discovered because of the string input param
Ryan
  • 5,456
  • 25
  • 71
  • 129
0

This one just bit me. I added a test to my project, but could not get it to show up in Test Explorer. My old tests all showed up. Finally, I realized I was only viewing a specific playlist, and I had not added the new test to the playlist. If you are using playlists, select "All Tests" and see if VS finds your tests and displays them in Test Explorer. Then you can add them to the desired playlist, too.

JNygren
  • 179
  • 1
  • 2
  • 20
0

Visual Studio Professional 2012, update 4 here. Having Interop function definitions (DllImport/extern) in the same project as test classes confused Test Explorer. Moving Interop into a separate project, resolved the issue.

mp31415
  • 6,531
  • 1
  • 44
  • 34
0

I encountered the same problem in VS2013 Ultimate. My problem was that I was creating a Windows Service and forgot to uninstall it. So the Service was running and VS couldn't access one of the DLLs which caused that the whole test suite wasn't loaded at all.

0

Here's another one to add to the list based on user error/stupidity.... I tried various answers from this question and then realised my test project was unticked in the Configuration Manager (Build menu, Configuration Manager) so it wasn't being built >.<

Posting this in the hope it'll save someone wasting an hour or two as I just did!

Matt
  • 12,569
  • 4
  • 44
  • 42
0

I was experiencing the same issue in Visual Studio 2013 Update 4 on Windows 7 SP1 x64 using a test project targeting the "Any CPU" platform configuration.

The problem was that the test project was actually named "Tests" and would disappear the second time the project was (re)built.

After I renamed the project to "MyProject.Tests" for example, the tests no longer disappear.

Rami A.
  • 10,302
  • 4
  • 44
  • 87
0

One issue I've run into repetitively is not running Visual Studio (explicitly) as Administrator on Windows 8+. I tried several of the suggestions listed, but they did not get the unit tests to appear until I ran VS 2013 as Administrator (even though my shortcut is set to open VS that way, either opening the solution file or sometimes clicking the shortcut it doesn't actually open as admin).

Aggromonster
  • 99
  • 2
  • 9
  • running as admin should not be necessary, unless microsoft have done something bad in the architecture of visual studio (so may be it is necessary. We should not be debugging programs as admin or with any significant privileges. – ctrl-alt-delor Mar 18 '15 at 18:43
0

Since none of these answers deal with the cause I encountered, for this problem, I will add my answer here as well.

In my case, it was a copy pasting code problem. We had a TestProjectA where there are specific type of tests that we want to pull out to its own test project - TestProjectB. The problem now was that, while tests in TestProjectA continue to show up just fine, the tests in the new TestProjectB aren't showing up in VS Test Explorer - unless you specifically build TestProjectB or manually right click on a test there and run it.

The cause was that in copy pasting the code over, some namespaces didn't get updated:

  • There is a TestMethodA() in TestClassA in namespace TestProjectA.ModuleA with filepath \TestProjectA\TestClassA.cs
  • As well as a TestMethodA() in TestClassB in namespace TestProjectA.ModuleA with filepath \TestProjectB\TestClassB.cs

So visual Studio prints out a message in Output window that the TestId for these two are the same, and proceeds to show TestProjectA and not TestProjectB in Test Explorer due to the TestId clashing between the two projects. Correcting the namespace to TestProjectB.ModuleB for \TestProjectB\TestClassB.cs fixed the issue.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
gspindles
  • 187
  • 6
0

This problem seems to have so many different solutions may as well add my own:

Close Visual Studio

Rename C:\Users\username\AppData\Local\Microsoft\VisualStudio\12.0\ComponentModelCache to ComponentModelCache.old

Run Visual Studio and the component cache will be rebuilt.

benPearce
  • 37,735
  • 14
  • 62
  • 96
0

Another issue that may prevent tests from being discovered, usually with a message in the Tests output window like:

Failed to configure settings for runsettings plugin 'VSTest Run Configuration' as it threw following exception:
'An error occurred while parsing EntityName. Line 1, position 8.'
Please contact the plugin author.

This can be caused by having characters in your path or file names that would need escaping to be parsed as xml. Specifically the & character, as < and > are not allowed in directory or file names. This causes the test discovery to fall over and not identify the tests, but I could still run the tests by hand using Resharper by clicking in the margin.

Patrick Allwood
  • 1,822
  • 17
  • 21
0

After googling "visual studio can't see tests" it brought me here, so I thought I'd share my problem. I could build my solution, and the tests existed, but I could not see them! It turns our it was a quirk of the IDE, that caused the problem. See image below for an explanation and fix:

enter image description here

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
Ben Power
  • 1,786
  • 5
  • 27
  • 35
0

The simplest thing you can do is, just drag and drop those files from the File Explorer to the Test project. Build the project again, and you are good to go!

OR

Open the .csproj file of your Test project in a text editor and manually include the file name to compile. Search for the Compile tag in the file and add your file which you want to run.

<ItemGroup>
    <Compile Include="TestSettings.cs" />
    <Compile Include="TestLibrary.cs" />
    <Compile Include="UnitTest1.cs" />
</ItemGroup>

Add the Compile tag for your file and save it. Now run the tests. Your file with unit test will be detected and run.

Teja
  • 1,236
  • 12
  • 27
0

The problem was that the test runner, is configured to not run tests from a remote drive. When I copied the project to a local drive it worked fine, but I needed it on a shared drive (can not remember why).

I read that it can be configured to work from a shared drive, but never got to do it as by the time I discovered the solution I had switched to MonoDevelop on Debian.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
0

I read all the existing answers and found that my (xUnit) tests weren't being discovered because I had removed 'unused' references and more specifically, xunit.execution.desktop. Re-installing the xUnit package fixed the issue in my case.

WynandB
  • 1,377
  • 15
  • 16
0

Visual Studio 2015 (v.14.....) - same problem here

Cause: Different versions of NUnit and NUnit Test Adapter In my case I had the latest versions of both NUnit (3.5) and NUnit Test Adapter but the Test Adapter was not the right one. For NUnit 3 and higher there is a NUnit3TestAdapter that must be used

Solution: Uninstalled the "faulty" NUnint Test Adapter and installed the UNit3TestAdapter v.3.5.0 (the latest now is 3.6.0 but didn't use it in order to keep it same as NUnit)

After Rebuild of the Solution Tests poped up :)

Angel
  • 90
  • 5
0

In my case, I had 3 test projects, created with Visual Studio 2017 (but I think it doesn't matter), and only two of them were discovered by the Test Explorer. I realized that the third project had a different version of the Microsoft.VisualStudio.QualityTools.UnitTestFramework dll. I updated it in the NuGet Manager and the tests appeared.

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
0

We were using xunit and solution worked for me and the team was deleting the folder %TEMP%\VisualStudioTestExplorerExtensions

Read this thread.

Why is the Visual Studio 2015/2017 Test Runner not discovering my xUnit v2 tests

Si Zi
  • 1,109
  • 10
  • 6
-1

You could right-click on a test method and choose the Run Tests/ Run unit Tests option. That should bring up the test windows.

leon
  • 762
  • 1
  • 10
  • 24
  • 1
    I right-clicked a test method. I see run tests ( I see this everywhere that I right-click code). I see no unit tests option. – ctrl-alt-delor Nov 23 '12 at 17:52
  • Try and re-add references to Microsoft.VisualStudio.TestTools.UnitTesting, rebuild and try again. Might be a something wrong with the project configuration. – leon Nov 23 '12 at 19:16