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

Bug #941727 reported by thirukumaran
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
NUnit Framework
Triaged
Wishlist
Unassigned

Bug Description

[This bug has been merged with and is now being tracked as https://github.com/nunit/nunit-framework/issues/68]

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.

Tags: github
Revision history for this message
Charlie Poole (charlie.poole) wrote :

I'm creating the tag 'dynamic_testcase' for requests that pertain to test case data which is not known until after the test begins to run. It's likely that we will define new attributes for this sort of data.

Changed in nunit-3.0:
status: New → Triaged
importance: Undecided → Wishlist
description: updated
tags: added: github
removed: testcasesource testcasesourceattribute
Revision history for this message
Ganesh (ganesh-swnt) wrote :

Hi Charlie,
Kindly let us know if this enhancement has been checkin and available to use.
Thanks, Ganesh.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.