Why does visual studio 2012 not find my tests?

2019-01-16 03:04发布

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

30条回答
Juvenile、少年°
2楼-- · 2019-01-16 03:19

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-16 03:20

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
查看更多
冷血范
4楼-- · 2019-01-16 03:20

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.

查看更多
Animai°情兽
5楼-- · 2019-01-16 03:22

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.

查看更多
冷血范
6楼-- · 2019-01-16 03:23

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.

查看更多
欢心
7楼-- · 2019-01-16 03:23

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

查看更多
登录 后发表回答