Why does visual studio 2012 not find my tests?
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 !
Related videos on Youtube
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, 2020Comments
-
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 referenceMicrosoft.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 nocreate 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 over 11 yearsWhich version VS 2012? You could download a test runner like TestDriven.Net or there is one in Resharper.
-
ctrl-alt-delor over 11 yearsI am using visual studio 2012 ultimate.
-
Adil over 11 yearsPlease share framework version and UnitTesting library version you have added as reference
-
Oleg Sych over 11 yearsThis should work out of the box. Please submit this at connect.microsoft.com/visualstudio with your code.
-
rahim123 almost 11 yearsIn my case removing the app.config file fixed the unit test explorer
-
Taras Alenin almost 11 yearsI have fixed this by giving full trust to the network share using
caspol
tool. Please see my answer below. -
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 about 10 yearsTry 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 almost 9 yearsMy issue was even simpler: My class wasn't public. (Hope that helps someone else hit their doh! moment quicker..)
-
live-love over 8 yearsJust rebuilding the test project did it for me.
-
Mateen Ulhaq about 8 yearsI was retarded enough to forget that I had selected a test playlist.
-
-
ctrl-alt-delor over 11 yearsI 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 over 11 yearsDoesn'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 over 11 yearsI 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 over 11 yearsTry and re-add references to Microsoft.VisualStudio.TestTools.UnitTesting, rebuild and try again. Might be a something wrong with the project configuration.
-
Brett Allred over 11 yearsI 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 about 11 yearsDid it for me, nearly embarrassing I didn't find out on my own :)
-
ctrl-alt-delor about 11 yearsYes 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 about 11 yearsThere 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 about 11 yearsthanks for your answer, it helps me (I switched from x86 builds to x64 builds)
-
Seph about 11 yearsI had this problem as well,mine was caused by the
[TestMethod]
being static because of a copy-paste of other code. -
Justin Morgan about 11 yearsWorked for me too! I think this is a separate issue.
-
rahim123 almost 11 yearsin 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 almost 11 years@Seph: My
[TestMethod]
s where static because that is what theUserTest1.cs
in the new test project had! Also solved my problem. -
ctrl-alt-delor almost 11 yearsI don't think this is the same problem.
-
ctrl-alt-delor almost 11 yearsThis 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 almost 11 yearsWhile 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 almost 11 yearsI think it IS the same problem, it's just caused by something else.
-
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 over 10 yearsThis 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 over 10 yearsHey this works man. Thank you very much.. Any workaround to make it work without running as administrator?
-
Dave over 10 yearsWow! 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 over 10 yearsSorry I don't think that running as admin is a good solution. Unless evidence that this is the only way.
-
ctrl-alt-delor over 10 yearsOK same symptoms, so will remove down-vote, if you make clear what you changed (from what).
-
Edward Olamisan over 10 yearsRunning as admin is usually not a big problem. But one of the issues is that you cannot send the Workitem to outlook.
-
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 about 10 yearsThis 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 about 10 yearsThis 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 almost 10 yearsIt 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 almost 10 yearsThank you.
UTA001: TestClass attribute defined on non-public class
-
Prageeth godage over 9 yearsI have done all of your steps + (put all my project dll to GAC then it works calm.)Thank you sir.
-
edelwater over 9 yearsI 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 over 9 yearsI 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 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 over 9 yearsEdited 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 over 9 yearsAlso don't put
static
in front of your method. I don't know why I do that out of habit so often. -
DJH over 9 yearsAlso available via NuGet
Install-Package NUnitTestAdapter
-
kaybee99 over 9 yearsThis was also the problem for me. So annoying that VS didn't pick them up but gave zero indication as to the cause!
-
Silas about 9 yearsor just skip the signature check on your local machine by
sn -Vr *,<public key token>
as adminstrator in VS developer command prompt -
Dan But about 9 yearsRight when I changed default processor -- all my tests showed. Thanks so much for this!
-
ctrl-alt-delor about 9 yearsrunning 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 almost 9 yearsThanks @DarrenHale. While searching for this package in NuGet, I also found a bundle called NUnit TestAdapter including NUnit 2.6.4 Framework.
-
Chris Hawkes over 8 yearsAs of VS2013 this still happens from time to time, some things with Microsoft never change.
-
Alex over 8 yearsThis 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 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 over 8 yearsEven in VS 2015 having the Test Explorer window open worked. Glad that I can also run tests from the command line.
-
Thulani Chivandikwa over 8 yearsThis 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 almost 8 yearsThanks for this - crazy how many times I tried the clean solution/build solution combination before I scrolled down to see this!
-
Teja almost 8 yearsAdded one more solution. Doing so, doesn't break anything :-)
-
Tim Partridge almost 8 yearsEnsure your test method is
public
too -
Robert Green MBA about 7 yearsA 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 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 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.