How do I start an application (specifically telemetry) as part of rebar3 eunit?

How do I start an application (specifically telemetry) as part of rebar3 eunit?

In particular, I want it started unconditionally. I do not want to add setup fixtures to all of my tests.

This project currently uses erlang.mk. and it’s as simple as this:

EUNIT_ERL_OPTS = -eval 'application:ensure_all_started(telemetry)'

(although I’ve actually got EUNIT_ERL_OPTS = -s test_helper, because I start a couple of other things in test_helper:start/0).

I’ve tried various combinations of ERL_FLAGS (seems to be ignored) and ERL_AFLAGS and ERL_ZFLAGS, but the paths aren’t set correctly, or it just doesn’t work.

But that’s clunky anyway – can I do it with rebar.config?

I should note that I’ve got it listed in my .app.src file:

    {applications, [
        kernel,
        stdlib,
        telemetry
    ]},

…but that doesn’t work, because rebar3 eunit doesn’t start my application anyway (and nor should it, by default).

So anyway, I wrote a plugin to do it: GitHub - rlipscombe/rebar3_eunit_start: A rebar plugin that allows you to run code before `rebar3 eunit` does its thing

That is the exact reason I don’t ever use eunit - all tests eventually evolve and they need some state/setup/teardown, so I always start with CT.

If eunit tests are already there and rewrite to CT is not an opiton, I’d wrap them in a CT suite and call eunit:test/1 in testsuites.

Does Common Test have a way to automatically start a list of applications before running the tests? I often needed this but haven’t found anything like that

Not that I know of, so I wrote one of those as well: GitHub - rlipscombe/ct_ext: Common Test Report Hooks (the repo description is wrong; it also has report hooks in it).

It can be done using CT hooks with pre_init_per_suite/3 callback