« Back to Index

[Go Test Mocking Package Function]

View original Gist on GitHub

Tags: #go #golang #mock #stub #testing #unittests #test

Go Test Mocking Package Function.md

Build Tags

File: a/a.go

// +build !mock

package a
func DoSomething() {
    return "done"
}

File: a/a_mock.go

// +build mock

package a
func DoSomething() {  // Insert fake implementation here
    return "complete"
}

Execute tests using build tag:

$ go test -tags mock