imocker

command module
v0.0.0-...-b8770ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2024 License: MIT Imports: 1 Imported by: 0

README

imocker

Go Reference Go Report Go Coverage

Overview

imocker is a tool designed to generate mock structs that implement an interface in order to effectively write unit tests using nothing but the standard library.

imocker generates actual Go code that can be used in unit tests without using strings to look up methods, without chaining function calls to compare expectations, and no ability to diverge from the interface implementation.

Installation

Go Install

go install github.com/mvlipka/imocker@latest

Usage

imocker
imocker generate ./...
imocker generate ./testdata

Examples

A small example can be seen in the testdata folder.
testdata/mock_thinger.go was generated by using imocker generate ./...

An interface such as

type Thinger interface {
	MyFunc(param string) (string, error)
	NamedReturn(multiple bool, types bool) (err error)
}

Will generate a mock such as:

type MockThinger struct {
	TestMyFunc func(param string) (string, error)
	TestNamedReturn func(multiple bool, types bool) (err error)
}

func (m *MockThinger) MyFunc(param string) (string, error) {
	return m.TestMyFunc(param)
}

func (m *MockThinger) NamedReturn(multiple bool, types bool) (err error) {
	return m.TestNamedReturn(multiple, types)
}

Current Limitations

  • MyMethod(multiple, vars bool) (error)
    • Methods with multiple parameters under a single type definition are unsupported
  • MyMethod(bool, bool) (error)
    • Methods with no parameter names defined are unsupported

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL