Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For the second example, the non-implementable public interface, is there a way to allow implementations when testing?

naively, if i define a non-implementable public interface as described in the article inside `foo.go` and put some test code next to it in `foo_test.go` that attempts to implement the interface with a special test version, then as we might expect, that doesn't work. if i put test code inside `foo.go` itself, `go test` doesn't appear to collect the test.

(i have no experience with go, apologies if i am missing something very obvious)



Your example of `foo.go` and `foo_test.go` would actually work the way you want. In go, tests are in the same namespace as the code they are testing so they have access to private members.


Ah, thank you. Where i was going wrong was declaring `foo_test.go` to be a separate package from `foo.go`. When i write `package foo` at the head of both `foo.go` and `foo_test.go` this works fine.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: