So while Visual Studio doesn’t support the [CategoryAttribute], it does have the rather useful [TaskPropertyAttribute]. This attribute allows you to define key/value pairs for a test. So, I guess I am going to be using “Category” as the key. Unfortunately, the command line version of the test tool only supports either listing every test individually (ick) or some weird proprietary TestList format. Oh, and guess what, you can only create TestLists with Visual Studio Team System Test Edition. Somehow, I sense this is going to be _fun_. Fortunately, I have an evaluation of VSTSTE (sounds like a disease) around here somewhere…

Hmm, I think I will leave this part till later, and go have a look in a mirror – yup, you guessed it, time to play with one of the best features of .net, Reflection. First of all, I need a way to load in the assembly I want and then I need to go through and look for Test Classes. Then, for each TestMethod, I need to grab the settings for the TestProperties…

Loading the assembly is easy:

Assembly asm = Assembly.LoadFrom(dllPath);

Now I can get a list of types:

Type[] types = asm.GetExportedTypes();

And for each Type, I can get a list of Methods:

MethodInfo[] type.GetMethodsBindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)

I’m only interested in TestMethods:

mi.GetCustomAttributes(typeof(TestMethodAttribute),true).Length > 0

And in particular, the TestProperties of those methods:

mi.GetCustomAttributes(typeof(TestPropertyAttribute), true)

Sweet – so that part was easy – I’m going to check this in now…

Post a comment or leave a trackback: Trackback URL.

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: