Recommended way to start a background worker only for certain integration tests?

I have a Phoenix app that has a background worker (Genserver) which is responsible for reading and writing to the DB. This worker (MyAppWeb.Workers.AccountWorker) runs once a second. It is located in MyAppWeb because it is responsible for broadcasting to the frontend (which is irrelevant for this question but may answer your question as to why it is under MyAppWeb).

I would like to selectively start this worker depending on the tests being run. For example, if the tests are for the account management than I’d like it to run, however if the integration tests are for messaging then no. I also do not want to run this worker for any of the non-web contexts/business-logic tests.

I was thinking of using Mox for swapping out the module per test but I’m wondering if there is a way to do this without Mox and with the least amount of updating all my tests.

Thank you

Do not start your application during tests (beware as Logger behaves funky then) and start it only when needed. From my experience a lot of applications can be tested without running whole application supervisor.

Thank you. I’ll look into it.