Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Introducing gomock

In this section, we will be introducing gomock [4], a very popular mocking framework for Go that leverages reflection and code generation to automatically create mocks based on Go interface definitions.

The framework and its supporting tools can be installed by running the following commands:

$ go get github.com/golang/mock/gomock
$ go install github.com/golang/mock/mockgen

The mockgen tool is responsible for analyzing either individual Go files or entire packages and generating mocks for all (or specific) interfaces that are defined within them. It supports two modes of operation:

  • Source code scanning: We pass a Gi file to mockgen, which is then parsed in order to detect interface definitions.
  • Reflection-assisted mode ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content