Created
January 7, 2014 10:07
-
-
Save karlseguin/8297287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// x.go | |
package di | |
var someCall = func() string { | |
return "original implementation" | |
} | |
func SomeMethodToTest() string { | |
return someCall() | |
} | |
// x_test.go | |
package di | |
import ( | |
"testing" | |
) | |
func TestSomeCall(t *testing.T) { | |
someCall = func() string { | |
return "mock" | |
} | |
if SomeMethodToTest() != "mock" { | |
t.Fail() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wonder how would you test dependencies from other packages - for example you have a web handler which calls a data layer methods... How do you manage dependency injection in such cases?