I use https://github.com/dsymonds/gomock which will generate a mock
that implements an interface that you specify, and allows you to
record expected calls against it.
It seems like there is a big over head when it comes to mocking something in Go.Unless Go allows developers to redefine methods on the fly, the language does not look very friendly to Test Driven Developers, comparing to other dynamic languages like Ruby or Javascript.
Do you guys know of any tutorial or example that talks about unit testing in Go and especially dealing with removing dependencies?Curse who named Go, Go. It makes it impossible to search for anything related to Go...
None of the examples linked here showed how to remove dependencies within unit tests.Maybe someone who is more experienced with Go can create a tutorial focusing on non-trivial unit tests in Go. That would be very helpful for the people coming from TDD background. :)
No, it's not possible because OCMock makes use of ObjC's metaprogramming abilities to create methods on an object at run-time. There may be some other technique to simplify the redundancy in implementation which we'll keep seeing, and the community seems to be working on this over time. But for now the solution is to write your own mocks and make careful use of interfaces. This is the only downside to having no meta-programming, but it's totally worth it, because in every other situation, magic sucks.-Steven
Here's an article on using the lambda approach:
http://openmymind.net/Dependency-Injection-In-Go/
Though so far I'm just using interfaces for doubles/fakes. I haven't gotten into mocking/expectations in Go yet.