How can i test an interface?

前端 未结 4 471
刺人心
刺人心 2021-01-07 09:13

I want to do a JUnit test case for an interface, as you know i can\'t make an object from the interface and i don\'t want any classes names to show up in that test, i want o

4条回答
  •  一整个雨季
    2021-01-07 09:41

    The only way to test an interface is to create a concrete class that implements it, instantiate it and test that class. You can't test an interface directly, because as you know, it can't be instantiated, leaving nothing to be tested. This should be obvious: an interface is just a collection of method signatures, with no method bodies - hence there is no behavior to be tested.

提交回复
热议问题