Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Does this answer your question? The need for adding an interface to every class Commented Oct 29, 2020 at 8:47
  • So if I want to create a test using this object, I need to write an interface? For me it would be an interface for Client, Invoice and Product since InvoiceLine is highly connected to Invoice? I think I'm not understanding something Commented Oct 29, 2020 at 9:00
  • 1
    Very, very few things are necessary. Commented Oct 29, 2020 at 22:35
  • 4
    @Awerde: can you create a full-fledged object of the production class to write your test? If so, there is no need to create an interface. You only need to "invert dependencies" when an object has dependencies that impede tests (like access to the internet, access to a database, random measurements of the outside world) and want to swap it for a controllable test stub. (In the context of writing tests for your code) Commented Oct 30, 2020 at 12:22
  • 1
    Well, should the method in Invoice know about the intimates of the Product class in order to add a line to an invoice? Do you want to create Product instances to test the Invoice class? If no, pass the values in as parameters instead. Commented Nov 2, 2020 at 16:02