C# NUnit TestCaseSource Passing Parameter

前端 未结 3 1669
予麋鹿
予麋鹿 2021-02-04 06:58

I have the following method which generates a set of test cases!

public IEnumerable PrepareTestCases(param1)
{
    foreach (string e         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 07:21

    I've made a change for this in the latest version of nunit which is about to be released (3.2).

    https://github.com/nunit/nunit/blob/4f54fd7e86f659682e7a538dfe5abee0c33aa8b4/CHANGES.txt

    • TestCaseSourceAttribute now optionally takes an array of parameters that can be passed to the source method

    It is now possible to do something like this

    [Test, Category("Integration"), TestCaseSource(typeof(MyDataSources),"PrepareTestCases", new object[] {param1})]
    public void TestRun(ResultsOfCallMyMethod testData)
    {
    // do something!
    }
    
    private class MyDataSources
    {
      public IEnumerable PrepareTestCases(param1)
      {
        foreach (string entry in entries)
        {
            yield return callMyMethod(param1);
        }
      }
    }
    

提交回复
热议问题