On Thu, Oct 1, 2020 at 6:25 PM Krishna C <krishnak...@gmail.com> wrote:
> > For unit tests, we need to mock the dependent interfaces either by > creating our own mock implementation of the interface or by using third > party packages like *testify/mocks.* > > Is there any particular reason as to why you want to mock dependent interfaces other than "best practices" ? The reason I'm asking is that whenever I have large cumbersome interfaces I find that these mocking endeavours end up in a lot of work for very little gain. In my experience, it is better to find an interface where the interface part is as small as possible. For example, look at the HTTP test system in the stdlib: There is a HTTPWriter hidden inside the response object, and it is fairly small. This interface is what can be replaced with another implementation for testing, but most of the interface actually stays the same when you use it. Another reason I'm asking is because it looks like you've stumbled into a set of large dependent interfaces and are now seeking a cookie cutter solution to the problem, namely mocking. If at all possible, restructuring your code to simplify it often avoids the need for mocking and makes unit-tests far easier to get along, but without code, it is hard to get an idea of what you are facing here. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAGrdgiXXExjZpdhDZWKE_jVHicmmOQNY-s-LYr1-8tGeuzHQBw%40mail.gmail.com.