0

I have many methods with different "Priority" attributes such as:

    [TestMethod]
    [Priority(2)]
    public void TestCase1()
    {
    }

    [TestMethod]
    [Priority(1)]
    public void TestCase2()
    {
    }

I'm able to get all of them but I don't know how to show their priority values

var assembly = Assembly.LoadFile(@"a.dll");

var testClasses = assembly.GetTypes().Where(c => c.GetCustomAttribute<TestClassAttribute>() != null);

foreach (var testClass in testClasses)
{
    using (var file = new System.IO.StreamWriter(@"C:\TestsList.txt", true))
    {
         file.WriteLine(testClass);
     }
     var testMethods = testClass.GetMethods().Where(m => m.GetCustomAttribute<TestMethodAttribute>() != null);
     foreach (var testMethod in testMethods)
     {
         using (var file = new System.IO.StreamWriter(@"C:\TestsList.txt", true))
         {
              file.WriteLine(testMethod);
         }
     }
}

Is it possible to do something like

testMethod.getPriority()
Mikk
  • 455
  • 1
  • 13
  • 19
  • 1
    In your loop, get the attributes of `testMethod` (see duplicate) and access the [`PriorityAttribute.Priority`](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.priorityattribute.aspx) property. – CodeCaster Aug 11 '14 at 13:21
  • I tried this but it couldnt get the priority attribute: var pAttr = (PriorityAttribute)method.GetCustomAttributes(typeof(PriorityAttribute), true)[0]; – Mikk Aug 11 '14 at 14:19
  • Then please update your question with that code and what it does and doesn't do, @mention me and I can reopen your question. – CodeCaster Aug 11 '14 at 14:43
  • 1
    @CodeCaster thanks for pointing me to that link, it is working now. Problem was that the dll being read is outdated hence I wasnt able to get the newly added added attribute in the code, which is the Priority. – Mikk Aug 11 '14 at 15:22

0 Answers0