0

I have a custom configuration section, and i'm constructing some unit tests for it. I'd like to be able to specify, somehow, different .config files programatically to test. Is there a way to do this?

5
  • what would be different within the different config files.. could you possibly add differect sections to the existing config file..? what do you have so far..? Commented Dec 15, 2011 at 18:08
  • Possible duplicate of stackoverflow.com/questions/360024/… Commented Dec 15, 2011 at 18:09
  • 1
    Possible dup stackoverflow.com/q/4738/706456 Commented Dec 15, 2011 at 18:12
  • @DJKRAZE -I have a custom configuration collection. I want to test that certain supplied config values throw an exception if they are invalid. However, this test will have the side-effect of breaking my other unit tests. The solution, in my mind, is to have a separate config file where I can supply invalid entries without breaking my other tests Commented Dec 15, 2011 at 18:33
  • 1
    @oleksii -I think the solution in that question will do the trick. Thank you! Commented Dec 15, 2011 at 18:34

1 Answer 1

1

I don't know what exactly your unit tests look like. If you have an app.config file in your unit test project where your custom configuration resides, a possible solution would be to open the configuration in a writeable mode and change the config values to your need. After the unit test, restore the old config values.

Use

ConfigurationManager.OpenExeConfiguration(...)

See also msdn

If you are looking for a unit testable configuration solutions try out DslConfig

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.