Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created June 27, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/09d8caa41656d8e8447c4c6d315cb99d to your computer and use it in GitHub Desktop.
Save Integralist/09d8caa41656d8e8447c4c6d315cb99d to your computer and use it in GitHub Desktop.
[Go Test Mocking Package Function] #go #golang #mock #stub #testing #unittests #test

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment