I consider myself to be a 'mockist' on the 'mockist' vs 'classicist' debate, but I am trying to understand the other point of view.
Imagine I have this class, where a concrete instance of IDependency
is injected by an IoC container.
IDependency
does not access a remote resource like a database or web service (in which case I would definately mock it), it is just another class containing some business logic.
public class UnitUnderTest
{
public UnitUnderTest ( IDependency dependency )
{
}
}
Using this pattern, I am free to change the concrete implementation of IDependency
by changing the class injected by the IoC container. I am not tied to any particular implementation.
If I was to test this class without mocking IDependency
, wouldn't I have to instantiate my real IDependency
to pass in to the constructor?
public class My_Unit_Test()
{
IDependency concreteDependency = new ConcreteDependency();
var unitUnderTest = new UnitUnderTest(concreteDependency);
}
In this example, if I write a replacement to ConcreteDependency
, I would have to not only change my IoC container configuration, but all of my unit tests that use ConcreteDependency
.
Or.. do I use the same IoC container within my unit tests (which seems like it goes against the idea of testing things in isolation)?
IDependency
were a concrete class, rather than merely an interface?