This is a dilemma. Say we have two classes
Class A
{
public int memberValue;
}
interface IB
{
int fun();
}
Class B : IB
{
public int fun()
{
var a = new A();
switch(a.memberValue)
{
case 1:
//do something
break;
case 2:
//do something
break;
}
}
}
Now this presents two tightly coupled classes. For testing B.fun(), we need to mock Class A and provide multiple values for A.memberValue.
As the A object is not required anywhere else beyond the scope of B.fun(), I dont see why should we inject it through B's constructor. How can we unit test this method fun() ?