Unit testing the app.config file with NUnit

后端 未结 13 2333
夕颜
夕颜 2020-12-04 16:37

When you guys are unit testing an application that relies on values from an app.config file? How do you test that those values are read in correctly and how your program re

13条回答
  •  余生分开走
    2020-12-04 17:03

    You can call the set method of ConfigurationManager.AppSettings to set the values required for that particular unit test.

    [SetUp]
    public void SetUp()
    {
      ConfigurationManager.AppSettings.Set("SettingKey" , "SettingValue");
      // rest of unit test code follows
    }
    

    When the unit test runs it will then use these values to run the code

提交回复
热议问题