Tutorial :Where is the [TestMethod] Attribute in TypeMock?



Question:

Ok, dumb question. I'm trying to set up my first TypeMock demo project in VS2005 but it doesn't recognize the [TestMethod] attribute. I've included both the TypeMock and TypeMock.ArrangeActAssert assemblies and I'm referencing them with "using" statements. Even intellisense can't find the attribute. What am I doing wrong here?


Solution:1

[TestMethod] is from the Visual Studio unit testing 'framework'. The following code shows basically how to use the attribute:

    using Microsoft.VisualStudio.TestTools.UnitTesting;    [TestClass]  public class MyTests  {      [TestMethod]      public void MyFirstTest()      {          Assert.AreEqual(1, 1);      }  }  

If you're using NUnit or another framework, the attributes are possibily different.


Solution:2

Which unit testing framework are you using? TestMethod sounds like the Visual Studio test system, while the NUnit counterpart is called Test.


Solution:3

I'm guessing that the TestMethodAttribute comes from MSTest, not TypeMock. So you should add a reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework

Edit: This is the namespace where the attribute is defined: Microsoft.VisualStudio.TestTools.UnitTesting;


Solution:4

[TestMethod] comes from the MSTest library not from the TypeMock framework


Solution:5

Assuming you're using MSTest, you must include [TestClass()] for the class and [TestMethod()] for the tests (don't know if parenthesis are needed).

TypeMock is a mocking framework, so you should worry first for what testing framework you're using.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »