I am using mocking in my unit tests in my code. My mocks are however, injected through
For example, if Application.get_env(:app, :httpclient) is
HTTPoison in my development and production, it would be a special dummy module called
HTTPoisionMock I created for testing purposes. This module has exactly the same API as HTTPoison but it’s function calls can be mocked.
Now, at the beginning of my test run, I need to
initialize these mocks, meaning, I need to call a
init() function on each of them so that they are “registered”.
I would like to see if there is a way for the for the
test_helper.exs to automatically get all the modules from
test/mocks/ directory and call
.init() on each of them?
currently I am manually maintaining a list of these modules and doing init in the following way:
mocks = [ Mocks.MailerMock, Mocks.AccountsMock, Mocks.HTTPoisonMock, ] Enum.each mocks, fn(m)-> m.init() end
I would like to get rid of all this manual maintenance and let the code do it.
Any help would be appreciated, thank you!