Below you will find pages that utilize the taxonomy term “TDD”
May 26, 2020
Gomock Tutorial
I’ve been using mock/Gomock
to write tests in my personal project. When you’re building something in a new
language, it is hard to prioritize learning every tool in your toolchain. For me, I’ve been writing custom and
suboptimal code for Gomock because of a nifty but undocumented API call .Do
.
In many cases, I wan to match subsets of a complex object while ignoring irrelevant parts. e.g., verify a function is
invoked with a list of User
objects, but only verifying the email addresses. To do that in a generic
way, I wrote a custom Matcher API that uses text/template
to describe what parts of the object to match. Thus, my
mock-and-verify code looks like: