← Back to team overview

nunit-core team mailing list archive

[Bug 941727] [NEW] Enhancement request: Get 'test method' name in a property which is called by TestCaseSource

 

Public bug reported:

I am trying to data drive by test using excel sheet. My requirement is 
 that based on the name of the test i need to pull appropriate data for 
 the test. 

In the code below inside TestCaseDataList i need to find out what is 
 the name of the test. Usually I use TestContext to get the test method 
 but this runs before the test is even run so can't use that. 

[TestFixture] 
     class TestSuite 
     { 
          [Test] 
          [TestCaseSource(typeof(MyFactoryClass), "TestCaseDataList")] 
             public void MyTestMethod(string apikey, string userid, 
 string productid) 
             { 
                 Console.WriteLine(apikey); 
                 Console.WriteLine(userid); 

Console.WriteLine(productid); 
             } 
     } 

    public class MyFactoryClass 
     { 
         public static IEnumerable<TestCaseData> TestCaseDataList 
         { 
             get 
                 { 
                     string mydata=""; 
                     mydata= GetTestMethodName().Tostring //Something 
 like this i need 
                     List<TestCaseData> testCaseDataList = 
 ExcelDataManager.GetExcelData(mydata); 

                    foreach (TestCaseData testCaseData in 
 testCaseDataList) 
                     { 
                         yield return testCaseData; 
                     } 
                 } 
         } 
     } 

}

Please help as soon as possible.

** Affects: nunit-3.0
     Importance: Undecided
         Status: New


** Tags: testcasesource testcasesourceattribute

-- 
You received this bug notification because you are a member of NUnit
Core Developers, which is the registrant for NUnit Framework.
https://bugs.launchpad.net/bugs/941727

Title:
  Enhancement request: Get 'test method' name in a property which is
  called by TestCaseSource

Status in NUnit Test Framework:
  New

Bug description:
  I am trying to data drive by test using excel sheet. My requirement is 
   that based on the name of the test i need to pull appropriate data for 
   the test. 

  In the code below inside TestCaseDataList i need to find out what is 
   the name of the test. Usually I use TestContext to get the test method 
   but this runs before the test is even run so can't use that. 

  [TestFixture] 
       class TestSuite 
       { 
            [Test] 
            [TestCaseSource(typeof(MyFactoryClass), "TestCaseDataList")] 
               public void MyTestMethod(string apikey, string userid, 
   string productid) 
               { 
                   Console.WriteLine(apikey); 
                   Console.WriteLine(userid); 

  Console.WriteLine(productid); 
               } 
       } 

      public class MyFactoryClass 
       { 
           public static IEnumerable<TestCaseData> TestCaseDataList 
           { 
               get 
                   { 
                       string mydata=""; 
                       mydata= GetTestMethodName().Tostring //Something 
   like this i need 
                       List<TestCaseData> testCaseDataList = 
   ExcelDataManager.GetExcelData(mydata); 

                      foreach (TestCaseData testCaseData in 
   testCaseDataList) 
                       { 
                           yield return testCaseData; 
                       } 
                   } 
           } 
       } 

  }

  Please help as soon as possible.

To manage notifications about this bug go to:
https://bugs.launchpad.net/nunit-3.0/+bug/941727/+subscriptions


Follow ups

References