Monday, December 5, 2011

MSTEST - UTA004: Illegal use of attribute on testmethod

Have you seem this error UTA004: Illegal use of attribute on testmethod. The TestMethodAttribute can be defined only inside a class marked with the TestClass attribute. while trying to run a mstest unit test.
The common scenario when this occurs is if there is a method with [TestMethod] attribute but the class in which it is defined does not have [TestClass] attribute.
However, even if you add the [TestClass] attribute and the error does not go away, the reason is that the class is not public.

Hence, make sure that the class is public and it has [TestClass] attribute.