NUnit retry dynamic attribute

前端 未结 2 1199
陌清茗
陌清茗 2021-01-19 07:46

Hello I want to pass the number of retries dynamically from app.config value.

The app.config has the following line:



        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 08:45

    A bit of work around, but you can use TestCaseSource attribute to create data driven test that will run numberOfRetries times

    [Test, TestCaseSource("GetNum")]
    public void Test(int testNum)
    {
    }
    
    private IEnumerable GetNum
    {
        get
        {
            int numberOfRetries = int.Parse(ConfigurationManager.AppSettings["retryTest"]);
            for (int i = 1; i <= numberOfRetries; ++i)
            {
                yield return new TestCaseData(i);
            }
        }
    }
    

    In test explorer you will see Test(1), Test(2), Test(3).

提交回复
热议问题