views:

172

answers:

2

I'm using Unity for dependency Injection. This seems to help when I'm testing my objects because I can mock out all dependencies. However, how am I supposed to test that my configuration is valid?

For example, I change the Unity configuration in the app.config, and of course, the project will build fine. My tests are currently only testing my objects, so they still work. But how can I be sure that the configuration isn't broken?

A: 

I use structuremap with configuration in code. So I can actually check the configuration directly (check if you get the appropiate types / object trees). If you are using .config files, I guess you can load the whole configuration section and hand it to unity (dunno if it supports it).

I also do automated functional tests, to test it fully integrated (instead of doing manual tests).

For web apps you can use selenium rc or watin, and have the tests in the same "unit" testing framework (keep them separate).

For desktop scenario, you could use automation.

eglasius
A: 

To update, what I've done here is keep my configuration in the app.config file. My test build event copies the app.config to its own app.config, then parses it to retrieve all dependency types. It then verifies that it can resolve all types as a test.

As a result, every time a change is made to the Unity configuration, the test verifies that all dependency types can be built. This eliminates most of my problems with dependency injection.

MikeHoyle