Resolution for C# Unit test project error : UTA002: TestClass attribute cannot be defined on generic class

if you ever have tried writing a generic class with attribute set to [TestClass] ass below , you might have got Runtime error which begin with “UTA002: TestClass attribute  cannot be defined on generic class”  & follows multiple such codes UTA004 or UTA005 or UTA006 for various Test method attributes

[Microsoft.VisualStudio.TestTools.UnitTesting.TestClass()]

public class CustomEntityTestBase<T> : CustomEntityBase<T>

{}

after trying multiple workarounds finally what made these errors go away is by putting an “abstract” keyword to the class declaration shown as below

[Microsoft.VisualStudio.TestTools.UnitTesting.TestClass()]

public abstract class CustomEntityTestBase<T> : CustomEntityBase<T>

{}

hoping this tip will save you a lot of time if you are struggling like me for this error and you don’t want to try complex workarounds as suggested in the internet

Advertisements
This entry was posted in C#, UnitTest and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s