jeudi 31 août 2017

Where to test default method implementation of superclass

I have fallowing classes:

Parent.java

interface Parent{
    void method1();

    default void method2(){
       //some default impl
    }
}

ChildOne.java

class ChildOne implements Parent{
    @Override
    void method1(){
        //ChildOne specific implementation
    }
}

ChildTwo.java

class ChildTwo implements Parent{
    @Override
    void method1(){
        //ChildTwo specific implementation
    }
}

Question is: where I should put a method 2 test? I know that for unit tests I should test concrete implementation so ChildOne and ChildTwo but when I have the same implementation of method2 I don't want to duplicate my test for it. However putting it into one of these classes don't seems to be good either.

Ofc, question is the same for abstract class with default implementation instead of interface.

Aucun commentaire:

Enregistrer un commentaire