visual studio 2010 - Generate testcategory based on vsmdi file -


i'm upgrading couple of big solutions visual studio 2010 visual studio 2012. want delete .vsmdi files unit tests. want use new testcategory attribute.

is possible generate test categories above test methods bases on list in vsmdi file? in example have lists "shoppingcart" , "nightly" , if test in vsmdi list, category set above method.

a simple find replace (multiple times per list?) solution. problem have couple of thousand tests 1 or multiple categories should placed.

thanks

i went through this. our vsmdi defined several lists , covered around 2500 tests. unfortunately couldn't find one-stop utility, did manage done quick , dirty console app in combination existing test list migration tool: http://testlistmigration.codeplex.com/

this extension produce test play lists vsmdi, smiple xml structure full test names. utility reads play list xml heapset, iterates each test file in directory, parses each method begins [testmethod], checks whether it's referenced in play list , if adds test category attribute. it's ugly, works , wrote in hour.

here c# code...and remember written hastily no regard aesthetic or best practice. solved problem , otherwise thrown away if not post :)

using system; using system.collections.generic; using system.io; using system.linq; using system.text; using system.text.regularexpressions; using system.xml; using testlistmigration.properties;  namespace testlistmigration {     class program     {         static void main(string[] args)         {             hashset<string> tests = new hashset<string>();             xmldocument doc = new xmldocument();             doc.load(settings.default.playlist);             xmlelement root = doc.documentelement;             xmlnodelist nodes = root.selectnodes("add");             foreach (xmlnode node in nodes)             {                 tests.add(node.attributes["test"].value);             }             directoryinfo di = new directoryinfo(settings.default.testpath);             foreach (fileinfo file in di.getfiles("*.cs",searchoption.alldirectories))             {                 var testfilereader =file.opentext();                 string filecontent = testfilereader.readtoend();                 testfilereader.close();                 bool dirty = false;                 var namespacematch = regex.match(filecontent, @"namespace ([a-za-z\.]*)");                 if (namespacematch.success){                     string namespacename = namespacematch.groups[1].value;                     var classnamematch = regex.match(filecontent, @"[\n\r\t ]*(public|internal|public sealed) class ([a-za-z0-9\.]*)");                     if (classnamematch.success)                     {                         string classname = classnamematch.groups[2].value;                         stringbuilder newfile = new stringbuilder();                         stringreader reader = new stringreader(filecontent);                         string line;                         while ((line = reader.readline()) != null)                         {                             newfile.appendline(line);                             if (line.contains("[testmethod]") || line.contains("[testmethod()]"))                             {                                 bool methodlineread = false;                                 stringbuilder buffer = new stringbuilder();                                 while (!methodlineread)                                 {                                     line = reader.readline();                                     buffer.appendline(line);                                     if (line.contains("void")){                                         methodlineread=true;                                         var testnamematch = regex.match(line, @"[\n\r\t ]*public void ([a-za-z\._0-9]*)\(\)");                                         if (testnamematch.success)                                         {                                             string fullname = namespacename + "." + classname + "." + testnamematch.groups[1].value;                                             if (tests.contains(fullname) && !buffer.tostring().contains("\t\t[testcategory(category." + settings.default.category + ")]"))                                             {                                                 newfile.appendline("\t\t[testcategory(category." + settings.default.category + ")]");                                                 dirty = true;                                             }                                         }                                     }                                 }                                 newfile.append(buffer.tostring());                             }                         }                         if (dirty)                         {                             file.writealltext(file.fullname, newfile.tostring());                         }                     }                 }             }         }     } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -