let’s say there is a Shape interface.
interface IShape { double Area(); }
A Rectangle class and a Triangle class implement it. Now should i write tests for:
- IShape interface and test both implementations in a single test file?
- Write tests for Rectangle and Triangle class separately, testing their implementation of Area() ?
- Do something else?
From what I see I am testing implementations either ways. How do you even test an interface without testing the implementation? Can someone please help clarify my doubts? Thanks!
Testing the interface is more like validating the architecture of your module.
Say, you have your interface IShape, which represents a geometric shape.
Now you decide to add some shape editing capabilities to your qpplication.
Can you rotate your IShape? Can you flip it? So your IShape interface needs methods rotate(double angle) and flip(enum direction). So you add a test that checks that your module exports methods rotate(double angle) and flip(enum direction).
Does your application requires rotating shapes by a fractional angle? Maybe rotating by 90⁰ is enough? So you replace rotate(double angle) with rotate90degrees(bool clockwise) in your test and you can simplify your implementation.