Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stub the Properties.Settings object when the unit test is in a different assembly?

I have an object the references a bunch of Properties.Settings.Default... values and I need to stub these in the unit test for this object.

Unfortunately the type for the settings object is declared as internal and so I can't access it from the unit test project.

How can I stub up the return values for these properties? I'm using Rhino Mocks for mocking.

like image 722
Glenn Slaven Avatar asked Dec 11 '09 03:12

Glenn Slaven


1 Answers

In general, I wouldn't. Instead of your "inner" objects actually reading Properties.Settings.Default, have them declare a cconfigurable property (either at construction time, or via properties), and have another piece of code populate them.

That way, you can test everything but the default reading stuff in your unit tests, and you become less coupled to a way of reading the defaults, making it easier to switch the mechanism in the future.

like image 144
kyoryu Avatar answered Sep 28 '22 09:09

kyoryu