Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 Not Recognizing Unit Test

In an existing solution I added a new Test Project. In my Test Project .cs file I have a class decorated with the [TestClass] attribute and a method decorated with the [TestMethod] attribute. I have verified that in Configuration Manager the build check box is checked for the Test Project (as my google search has revealed was the problem for others with this issue). I have set Test Project as my start up project for the solution. When I try to start the test I get "Can not start test project because the project does not contain any tests". I am really new to unit testing. What am I missing?

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
       Whole bunch of stuff
       Assert.Inconclusive("Done");
    }
 }

Update: So I opened a new instance of VS, went to File => New => Project => Test Project. Did not touch or edit anything. Went straight to the cs file and here are its contents in its entirety:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject2
{
 public class Inspection
 {
    public bool SubmitInsp()
    {
        return true;
    }
 }

 [TestClass]
 public class UnitTest1
 {
    [TestMethod]
    public void TestMethod1()
    {
        Inspection insp = new Inspection();
        bool result = insp.SubmitInsp();

        Assert.IsTrue(result);
    }
 }
}

Same error about the project not containing any test when I try to start it. Also found this in the build output "Could not load file or assembly '~\my documents\visual studio 2010\Projects\TestProject2\bin\Debug\TestProject2.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"

I don't know that units tests get much simpler than this. What the heck???

like image 481
jmease Avatar asked Aug 29 '12 15:08

jmease


1 Answers

I've had the same problem, when tests in an working test project suddenly weren't recognized anymore.

Comparing the project file with one from another working test project showed me that the <ProjectTypeGuids> node was missing from the main <PropertyGroup> node.

Adding this line inside the <PropertyGroup> node solved my problem:

C#:

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

VB:

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
like image 50
ranthonissen Avatar answered Nov 15 '22 10:11

ranthonissen