Posts

Showing posts from August, 2020

Go: Interface Mocking With Mockc

Introduction There are so many mocking libraries in Go ecosystem. But most of them are very difficult to use and learn. I think the main reason is they force you to use specific functions for assertion. Even if those functions provide powerful features, they are usually not intuitive and type-safe. So, I created a simple mock generator so that you could test your code in an intuitive way. And its name is ' Mockc ' . Let's take an overview! Overview It provides two ways for generating mock. In this post, I'll only cover the way using Mock Generator . Before we get started, install the command-line tool mockc first! go get github.com/KimMachineGun/mockc/cmd/mockc Then you'll get mockc installed in your $GOPATH/bin . This is our target interface and simple implementation of it. // cache.go package main type Cache interface { Get(key string) (val interface{}, err error) Set(key string, val interface{}) (err error) Del(key string) (err error) } type MapC