Skip to content
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

Move tests to _test package #74

Open
briggySmalls opened this issue Dec 15, 2020 · 2 comments
Open

Move tests to _test package #74

briggySmalls opened this issue Dec 15, 2020 · 2 comments
Labels
refactor Changes that don't affect functionality

Comments

@briggySmalls
Copy link
Owner

Apparently it is possible to put tests both alongside the source they test and in a different package (as long as it is suffixed 'test').

This is good because it prevents one from testin internals

@briggySmalls
Copy link
Owner Author

An interesting implication of this is that all the New methods would need to be used in the tests.

At the moment I have a pattern where lower-level AWS service clients are instantiated within a New call from the session which is passed in. The unit tests then, in order to inject mocks, don't use the New call, instead creating an internal struct instance.

Using a _test package would make this impossible, requiring AWS instances to be injected.

@briggySmalls
Copy link
Owner Author

It would probably be necessary to move mocks to a separate mocks directory/package. Which might be quite nice (easy to .gitignore and clean).

The impulse here would be to move mocks to a the test package too. But this doesn't work:

found packages email (email.go) and email_test (mock_ses.go) in /Users/sambriggs/Code/go/detectordag/shared/email

Note that it doesn't complain that email_test.go has the package email_test, just that mock_ses.go does. That's because it seems there is some check on the filename.

@briggySmalls briggySmalls added the refactor Changes that don't affect functionality label Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Changes that don't affect functionality
Projects
None yet
Development

No branches or pull requests

1 participant