Publishing mocks in production code

Mocks and stubs are tools for testing; as such, they should only ever exist in test code. In Go, this means an _test.go file. I have seen many well-meaning folks publish interfaces and their mocks in production code. The first problem with this is that it introduces a possibility, however remote, of this code ending up in production. Depending on where in the system this mistake was located, the results could be disastrous.

The second problem is a little more subtle. When publishing the interface and mock, the intent is to reduce duplication, which is fantastic. However, this also increases dependence and resistance to change. Once this code is published and adopted by others, modifying it will require changing all usage of it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.218.221