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).
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
andbin
directories and do a rebuild.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):
To verify or list existing trusted locations run:
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.
Quick check list for solving some common test problems. Make sure that:
public
[TestClass]
attribute[TestMethod]
attributeIf this does not help, try cleaning, rebuilding solution and restarting Visual Studio.
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 theOutput
window and selecting "Tests
" in the drop down. The error message was there. This was a pain... I hope it helps someone else.I've updated VS 2012 to the Latest Update . ie visual studio update 3. That fixed the issue for me.