Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using app.config in MBunit test

Tags:

c#

mbunit

gallio

The way I have my unit test set up is that a user can run the executable and select a dataset to use. This information is stored in app.config, however when I try to access app.config when running the unit test with Gallio Icarus it doesn't work.

Edit: I got the field to bind to an Application property however when I call Properties.Settings.Default.Save(); it doesn't seem to do anything. The app.exe.config does not change and the changes does not persist.

like image 669
Reflux Avatar asked Apr 28 '26 02:04

Reflux


1 Answers

Mock how you read the app config.

In your app write an interface & class that gets data from the app.config file. In your test, implement the interface on a dummy object, that will pass back known outputs each time.

The class that you're testing needs to take a parameter (on ctor or other) that is an object that implements the interface.

In your real code this will be the real object that reads from the app.config.

In the tests it will be the dummy object.

like image 148
Binary Worrier Avatar answered Apr 30 '26 15:04

Binary Worrier