Coder Perfect

Why is it that Visual Studio 2012 is unable to locate my tests?

Problem

Some of my tests make advantage of Microsoft’s built-in features. VisualStudio. TestTools. I’ve tried UnitTesting but haven’t been able to get them to run.

Visual Studio 2012 Ultimate is what I’m using.

I have a solution that consists of two projects: one contains testing and the other uses Microsoft. VisualStudio.TestTools. [TestClass] comes before the class, [TestMethod] comes before the test methods, and [Reference] comes before the reference. Microsoft.VisualStudio.QualityTools.UnitTestFramework is a Microsoft.VisualStudio.QualityTools.UnitTestFramework class (version 10.0.0.0, runtime version v2.0.50727). I’ve tried.NET Framework 3.5, 4, and 4.5, but all of them result in a re-targeting issue.

I attempted to construct the solution and project. The message ‘Build your solution to discover all available tests’ appears in the Test Explorer. To create, discover, and execute all tests in your solution, click “run all.”

So here’s the question: how can I get Visual Studio to look for the tests?

I’ve also attempted to follow this link: http://msdn.microsoft.com/en-US/library/ms379625% 28v=VS.80% 29.aspx however, without success: When I’m asked to right-click and select Create Tests under the section Getting Started, I get stuck. There isn’t a way to make tests.

I have the following test (which compiles but does not appear in the test explorer):

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace tests {
    [TestClass]
    public class SimpleTest {
        [TestMethod]
        public void Test() {
            Assert.AreEqual("a","a", "same");
        }
    }
}

I’ve now realised (see deleted response below) that it’s because it’s on a shared disc, but I’m not sure how to get around it. (Perhaps something to do with the security settings).

Asked by ctrl-alt-delor

Solution #1

I had the same symptoms as you, although in a different situation.

To Peter Lamberg’s solution, I had to add one more step: Clean your solution/project.

x64 is the target platform for my unittest project. The project was designed with x86 in mind when I started it.

All of my unit tests vanished after I switched to x64.

I had to go to the Test Menu -> Test Setting -Default Processor Architecture -> x64 to solve the problem.

They still haven’t arrived.

Did a build.

He hasn’t shown up yet.

Finally, I completed a Clean

Then they appeared.

When the settings have changed, I find Clean Solution and Clean to be very helpful in getting the solutions to cooperate. I occasionally have to go to extremes and erase the obj and bin directories before rebuilding.

Answered by Ourjamie

Solution #2

Please include the keyword public in the definition of your class. Outside of its own assembly, your test class is currently invisible.

namespace tests {
    [TestClass]
    public class SimpleTest {
        [TestMethod]
        public void Test() {
            Assert.AreEqual("a","a", "same");
        }
    }
}

Answered by Joe King

Solution #3

This sometimes works.

Verify that the processor architecture listed in the Test menu corresponds to the one you used to create the solution.

Default Processor Architecture -> x86 / x64 -> Test -> Test Settings -> Default Processor Architecture -> x86 / x64

Make sure the Test Explorer window is open, as indicated in previous blogs. -> Windows -> Explorer -> Test

The tests should then appear in Test Explorer after rebuilding the project with the tests.

Edit: As Ourjamie mentioned below, a clean build may also be beneficial. Aside from that, here’s something else I came across:

In Configuration Manager, I had unticked the “Build” button for a new test project I had established beneath the solution.

To access the Configuration Manager, go to Build -> Configuration Manager. Check the build checkbox for all solution configurations and solution platforms in your test project.

Answered by Peter Lamberg

Solution #4

I’m using Visual Studio 2012 and I’m having trouble seeing the tests in Test Explorer.

As a result, I set up the following: Adapter for NUnit tests

That solved the problem for me!

Answered by dnnyz

Solution #5

All of the above did not work in my recent experience. My way of testing

public async void ListCaseReplace() { ... }

Although it wasn’t displaying up, it was compiling correctly. The test appeared in the Test Explorer after I removed the async keyword. Because async void is a ‘fire-and-forget’ method, this is the case. You’ll get your test back if you make the function async Task.

Furthermore, failing to set the Test project’s configuration to “Build” will prevent tests from appearing. Check your Test to build in Configuration Manager.

Answered by MoonKnight

Post is based on https://stackoverflow.com/questions/13533259/why-does-visual-studio-2012-not-find-my-tests