samedi 30 mai 2015

Why is using static methods not good for unit-testing?

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?

Aucun commentaire:

Enregistrer un commentaire