I have an application that is using mimic in its unit test. I want to start the application while running unit tests. On application start there is a genserver that polls an external service. I want to globally stub out that request such that the genserver that starts with the application does not reach out to the external service on application start when running unit tests. below is how i have attempted to use mimic to stub the function in test helpers. unfortunately the stub is not global and the genserver started on application start is using the real implementation.
Application.ensure_all_started(:mimic)
Mimic.copy(Application.ExternalService)
Mimic.stub(Application.ExternalService, :get_messages, fn _, _ -> [] end)
# Ensure the application is started after stubbing
{:ok, _} = Application.ensure_all_started(:application)
ExUnit.start()
then i start the test using the --no-start flag