What is GoMock?

Overview of a mocking framework for Go with code examples
16 August 2017   4226

GoMock is a mocking framework for the Go programming language. It integrates well with Go's built-in testingpackage, but can be used in other contexts too.

Installation

Run these commands to install the gomock package and the mockgen tool:

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

Four steps of GoMock usage:

  1. Use mockgen to generate a mock for the interface you wish to mock.
  2. In your test, create an instance of gomock.Controller and pass it to your mock object’s constructor to obtain a mock object.
  3. Call EXPECT() on your mocks to set up their expectations and return values
  4. Call Finish() on the mock controller to assert the mock’s expectations

mockgen has two modes of operation: source and reflect. Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that may be useful in this mode are -imports and -aux_files.

Example:

mockgen -source=foo.go [other options]

Reflect mode generates mock interfaces by building a program that uses reflection to understand interfaces. It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols.

Example:

mockgen database/sql/driver Conn,Driver

Learn more at GiHub and with tutorial

GoLand 2018.3 to be Released by JetBrains

New version of IDE for Go programming language has a lot of new features
22 November 2018   530

Team JetBrains introduced a new version of IDE GoLand 2018.3. In this update, users will see:

  • refactoring by changing the signature;
  • memory dump;
  • Testify support;
  • new debugger tools;
  • Improved verification, prediction and code completion;
  • chart support;
  • updates for VCS, Docker, Kubernetes.

The new method of processing the code Change Signature will allow a single action to change the signature of functions and methods throughout the workspace. The function will show what will change in the code after application. The Inline tool will highlight the embedded code, and Rename will notify you of possible conflicts when renaming.

Added the ability to run and debug Google App Engine applications locally.

Go memory dumps are now available via Run / Open Core Dump directly in the IDE. To automatically create memory dumps, you need to enter GOTRACEBACK = crash in the Environment field.

Also, GoLand 2018.3 supports the Mozilla debugger rr, which allows you to search for a crash in the program by playing back its execution.

Get more info at official blog.

The previous version of GoLand 2018.2 was released in July 2018.