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条回答
再贱就再见
2楼-- · 2019-01-16 03:24

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.

查看更多
三岁会撩人
3楼-- · 2019-01-16 03:26

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.

查看更多
爷、活的狠高调
4楼-- · 2019-01-16 03:27

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.

查看更多
迷人小祖宗
5楼-- · 2019-01-16 03:27

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.

查看更多
闹够了就滚
6楼-- · 2019-01-16 03:28

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

查看更多
再贱就再见
7楼-- · 2019-01-16 03:28

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.

查看更多
登录 后发表回答