Why does visual studio 2012 not find my tests?

119,469

Solution 1

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.

Solution 2

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.

Solution 3

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");
        }
    }
}

Solution 4

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.

Solution 5

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 !

Share:
119,469

Related videos on Youtube

ctrl-alt-delor
Author by

ctrl-alt-delor

A software engineer, programmer, project manager, Gnu+Linux user, Newly Qualified Teacher of computing. I am currently hanging out on A new site for computer science and IT educators. Visit the site here

Updated on April 24, 2020

Comments

  • ctrl-alt-delor
    ctrl-alt-delor about 4 years

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

    • Brett Allred
      Brett Allred over 11 years
      Which version VS 2012? You could download a test runner like TestDriven.Net or there is one in Resharper.
    • ctrl-alt-delor
      ctrl-alt-delor over 11 years
      I am using visual studio 2012 ultimate.
    • Adil
      Adil over 11 years
      Please share framework version and UnitTesting library version you have added as reference
    • Oleg Sych
      Oleg Sych over 11 years
      This should work out of the box. Please submit this at connect.microsoft.com/visualstudio with your code.
    • rahim123
      rahim123 almost 11 years
      In my case removing the app.config file fixed the unit test explorer
    • Taras Alenin
      Taras Alenin almost 11 years
      I have fixed this by giving full trust to the network share using caspol tool. Please see my answer below.
    • mejdev
      mejdev almost 11 years
      @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)
    • gDexter42
      gDexter42 about 10 years
      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
    • Gene
      Gene almost 9 years
      My issue was even simpler: My class wasn't public. (Hope that helps someone else hit their doh! moment quicker..)
    • live-love
      live-love over 8 years
      Just rebuilding the test project did it for me.
    • Mateen Ulhaq
      Mateen Ulhaq about 8 years
      I was retarded enough to forget that I had selected a test playlist.
  • ctrl-alt-delor
    ctrl-alt-delor over 11 years
    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?
  • Adil
    Adil over 11 years
    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...
  • ctrl-alt-delor
    ctrl-alt-delor over 11 years
    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.
  • leon
    leon over 11 years
    Try and re-add references to Microsoft.VisualStudio.TestTools.UnitTesting, rebuild and try again. Might be a something wrong with the project configuration.
  • Brett Allred
    Brett Allred over 11 years
    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?
  • landi
    landi about 11 years
    Did it for me, nearly embarrassing I didn't find out on my own :)
  • ctrl-alt-delor
    ctrl-alt-delor about 11 years
    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
    ctrl-alt-delor about 11 years
    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.
  • enguerran
    enguerran about 11 years
    thanks for your answer, it helps me (I switched from x86 builds to x64 builds)
  • Seph
    Seph about 11 years
    I had this problem as well,mine was caused by the [TestMethod] being static because of a copy-paste of other code.
  • Justin Morgan
    Justin Morgan about 11 years
    Worked for me too! I think this is a separate issue.
  • rahim123
    rahim123 almost 11 years
    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!
  • Andre Luus
    Andre Luus almost 11 years
    @Seph: My [TestMethod]s where static because that is what the UserTest1.cs in the new test project had! Also solved my problem.
  • ctrl-alt-delor
    ctrl-alt-delor almost 11 years
    I don't think this is the same problem.
  • ctrl-alt-delor
    ctrl-alt-delor almost 11 years
    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
    ctrl-alt-delor almost 11 years
    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.
  • Stephan Bauer
    Stephan Bauer almost 11 years
    I think it IS the same problem, it's just caused by something else.
  • Stephan Bauer
    Stephan Bauer almost 11 years
    @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!
  • Travis Swientek
    Travis Swientek over 10 years
    This turned out to be the problem for me, but not the solution. I moved everything local and all the tests were found! Thanks!
  • Sriram Sakthivel
    Sriram Sakthivel over 10 years
    Hey this works man. Thank you very much.. Any workaround to make it work without running as administrator?
  • Dave
    Dave over 10 years
    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!
  • ctrl-alt-delor
    ctrl-alt-delor over 10 years
    Sorry I don't think that running as admin is a good solution. Unless evidence that this is the only way.
  • ctrl-alt-delor
    ctrl-alt-delor over 10 years
    OK same symptoms, so will remove down-vote, if you make clear what you changed (from what).
  • Edward Olamisan
    Edward Olamisan over 10 years
    Running as admin is usually not a big problem. But one of the issues is that you cannot send the Workitem to outlook.
  • Michael R
    Michael R about 10 years
    "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!
  • ctrl-alt-delor
    ctrl-alt-delor about 10 years
    This will fix the problems of most of the visitors to this question, and summarises most of the answers, however it does not cover the problem in the question.
  • Ben H
    Ben H about 10 years
    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.
  • julealgon
    julealgon almost 10 years
    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 which explains why this happens.
  • Jarek Przygódzki
    Jarek Przygódzki almost 10 years
    Thank you. UTA001: TestClass attribute defined on non-public class
  • Prageeth godage
    Prageeth godage over 9 years
    I have done all of your steps + (put all my project dll to GAC then it works calm.)Thank you sir.
  • edelwater
    edelwater over 9 years
    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.
  • John Reilly
    John Reilly over 9 years
    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...)
  • EpicVoyage
    EpicVoyage over 9 years
    CasPol.exe can be found under %windir%\Microsoft.NET\Framework[64]\[version]. Verify that you are setting the policy for the proper architecture. Source: msdn.microsoft.com/en-us/library/cb6t8dtz%28v=vs.100%29.aspx
  • Steven Jeuris
    Steven Jeuris over 9 years
    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.
  • levininja
    levininja over 9 years
    Also don't put static in front of your method. I don't know why I do that out of habit so often.
  • DJH
    DJH over 9 years
    Also available via NuGet Install-Package NUnitTestAdapter
  • kaybee99
    kaybee99 over 9 years
    This was also the problem for me. So annoying that VS didn't pick them up but gave zero indication as to the cause!
  • Silas
    Silas about 9 years
    or just skip the signature check on your local machine by sn -Vr *,<public key token> as adminstrator in VS developer command prompt
  • Dan But
    Dan But about 9 years
    Right when I changed default processor -- all my tests showed. Thanks so much for this!
  • ctrl-alt-delor
    ctrl-alt-delor about 9 years
    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.
  • ray
    ray almost 9 years
    Thanks @DarrenHale. While searching for this package in NuGet, I also found a bundle called NUnit TestAdapter including NUnit 2.6.4 Framework.
  • Chris Hawkes
    Chris Hawkes over 8 years
    As of VS2013 this still happens from time to time, some things with Microsoft never change.
  • Alex
    Alex over 8 years
    This was the cause of my problem. I had a field for the dependency interface as a private field. You are a life saver!
  • ctrl-alt-delor
    ctrl-alt-delor over 8 years
    @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.
  • Bryan
    Bryan over 8 years
    Even in VS 2015 having the Test Explorer window open worked. Glad that I can also run tests from the command line.
  • Thulani Chivandikwa
    Thulani Chivandikwa over 8 years
    This did it for me, interesting how you can lose so much time on something that should have been so obvious. Thanks for the answer Joe King
  • peppermcknight
    peppermcknight almost 8 years
    Thanks for this - crazy how many times I tried the clean solution/build solution combination before I scrolled down to see this!
  • Teja
    Teja almost 8 years
    Added one more solution. Doing so, doesn't break anything :-)
  • Tim Partridge
    Tim Partridge almost 8 years
    Ensure your test method is public too
  • Robert Green MBA
    Robert Green MBA about 7 years
    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(); }
  • Shiran Jayawardena
    Shiran Jayawardena about 7 years
    @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 :-)
  • Massimiliano Kraus
    Massimiliano Kraus about 7 years
    "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.