Skip to content

Export TestDouble Function in Hex Package #35

@nelsonic

Description

@nelsonic

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 the elixir-auth-google package and if MIX_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
software-engineering-question

Asking questions is the only way to learn. If you aren't asking questions you aren't learning.

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions