0

I have a fairly large Coded UI test and have set up each task in its own .cs class file. The main objective of the test is to check that objects have loaded on various pages in a browser. The test is set up to loop through an XML config file and invoke each method listed in the XML as the user sees fit.

Because I don't want every test method to run every time, I do not have the [TestMethod] attribute declared at the top of each class/method. Unfortunately, this means that each method that is invoked will not show up individually in the test results view, which is a big disadvantage.

Is there a way that I can apply the [TestMethod] attribute each time a method is invoked, but only for the methods I want?

Eric
  • 146
  • 2
  • 3
  • 9
  • If question is about logging which method was called then what about attaching some logger? In your scenario - MSTest works through reflection, so you need to somehow add `TestMethod` attribute to methods and feed modified assembly to MSTest. – nikita Mar 22 '13 at 12:56
  • Thanks, but it's not about logging. I am using a streamwriter object to write a .txt file which lists each method that was called. The main topic I am focusing on here is the test results view. Because I am not using [TestMethod], I cannot view each method which was called in the test view once the test has finished. – Eric Mar 22 '13 at 14:03
  • Output to `Console` in tests is showed in Test Results. – nikita Mar 22 '13 at 15:38
  • You will have to use ordered tests in VS 2010. However, this is no a recommended practice. – Zee May 08 '13 at 20:06

1 Answers1

0

The test runner uses reflection on the test assemblies to find methods with the [TestMethod] attribute and then calls those methods one by one to execute the tests. To do what you want you'd need to change the test runner, and even then you'd have to do something to change the IL of the test assemblies to dynamically add the attributes, reload the assemblies, and probably a whole lot of other things I'm glossing over. You'd basically be writing your own test framework if you got that far.

Instead, is there a reason you don't want to use test lists? They do what you seem to be asking for.

Richard Banks
  • 12,456
  • 3
  • 46
  • 62