I heard that creating object with static methods is not good for unit-testing. For instance, we have the following hierarchy:
public abstract class Base{
public static Base createConcrete(){
return new Concrete();
}
public static Base createSuperConcrete(){
return new SuperConcrete();
}
}
public class Concrete extends Base { }
public class SuperConcrete extends Base { }
It's better use instance FactoryMethod instead. Why does using static methods cause too much pain in unit tests? Couldn't someone give an example?
static, because your clients will already be tied to the method names which name the actual class being instantiated.staticmethods cannot be overridden, so a unit test cannot supply different mock objects for different tests.