DEV Community

Discussion on: Is testability a reason to change your design?

Collapse
 
eljayadobe profile image
Eljay-Adobe

"Unit tests are not, however, a good reason to change the interface of your design. If you make certain methods public because it increases testability, you create an overly complicated interface and confuse the programmers who work with your class/interface/function/whatever-abstraction."

I've only ever changed the interface of my design because of unit tests.

Not by making certain methods public to increase testability -- that's backwards. (Unit tests should only need to test the public API. Exposing internals in order to make them public API in order to test them is just... wrong. And it makes the internals more rigid BECAUSE OF THE UNIT TESTS, which make them waaaaay hard to refactor.)

By decoupling the dependencies, which in turn changes the interface.