-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: testing: allow importing API from _test.go functions in other tests #39565
Comments
It seems to me that using a common package is the right approach. Presumably when we import a package we don't normally want to be able to refer to testing functions. Even from test code, we normally want to use the standard package API, not a testing API. So if we were to support this, we would need some additional mechanism to say "import the testing API for package foo". But few people would ever use that mechanism. Since the need is unusual, and there is a way to do it by using a shared package, I don't see a compelling reason to add this feature. |
Hi @ianlancetaylor, even when I use a shared package I still have to include test-only code along with production code so it can be seen and used by other packages, which seems like a bad practice. |
duplicate of the previously declined #31135 ? |
It is common for packages to expose standard API that is mainly useful for testing. |
No change in consensus, so declined. |
What version of Go are you using (
go version
)?1.14
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?GOOS="darwin"
GOARCH="amd64"
What did you do?
In order to make it visible for tests that are located on different packages, I had to move a common database mock to a non
_test.go
file.You can view it here:
https://github.com/fernandomachado90/go-transactions/blob/master/core/database_mock.go
What did you expect to see?
I wanted to be able to import and use common
_test.go
functions on different packages.What did you see instead?
In order to avoid code duplication and reuse the same mock code in other places I have to make it available outside a
_test.go
file, which works but seems odd.The text was updated successfully, but these errors were encountered: