-
Notifications
You must be signed in to change notification settings - Fork 43
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
Export TestDouble Function in Hex Package #35
Comments
I like this idea. Having an test example as documentation for the users should be enough for them to cover the authentication testing. At the moment I don't see any cases where the users would want to customise the return values of the mock but it could be added later on if necessary. |
Sadly, Module attribute based dependency injection did not work. |
PR: #36 |
Meanwhile, there are a couple of answers on my original SoftwareEngineering question. |
At present we are not explicitly exporting the Mock version of HTTPoison in our Hex package.
Which means that the we need to have a Mock implementation in each "consumer" project.
See: https://github.com/dwyl/auth-mvp/blob/9836d31b501a731fcedfdd8a0d4fe026d105bda2/lib/mock/elixir_auth_google.ex#L1-L27
I propose that we take this a step further and actually check the
MIX_ENV
in theelixir-auth-google
package and ifMIX_ENV=test
we return the Mock version of the functions.e.g: https://github.com/dwyl/elixir-auth-google/blob/master/lib/httpoison/in_memory.ex
This way the person using the package never has to think about creating their own mocks and simply copy-paste the sample tests to achieve 100% test coverage in their project.
I don't know if this is an "anti pattern" or a "best practice" so I've opened a question to find out:
https://softwareengineering.stackexchange.com/questions/408267/is-it-a-best-practice-or-anti-pattern-to-export-mock-versions-of-functions-for-a
I think I want to export the Mocks regardless of what other people say - because I don't want to have to duplicate this code in the Auth project - but I'm curious what the "best practice" is.
The text was updated successfully, but these errors were encountered: