Question

The component I'm developing has to interface with several external systems. I don't want to interact with the external systems when I'm running unit tests, just when we're doing integrated testing (or production, of course!) :-) In its most ugly-looking-form, it would be something along the lines of:

if (<Flag in App.config> == true)
{
    // get result from external system
}
else
{
    // get a mocked-up result
}

Is there an example of a better way to implement something like this using dependency injection so my code doesn't have to be polluted with IF-statements? I was looking at using MEF because it's included in the .NET Framework.

Was it helpful?

Solution

MEF is not a framework for unit testing, it is for extensiblily, to let others write plug-in for your software.

As I think, you should look into dependency IoC containers, here's a list of IoCs for .NET.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top