Created
January 7, 2014 10:07
-
-
Save karlseguin/8297287 to your computer and use it in GitHub Desktop.
This file contains hidden or 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() | |
} | |
} | |
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?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't this be a problem, if another test in the same package happens to override
someCall
method?Redefining
someCall
method is not scope protected if it's in the same package?