I have hit an issue with Common Test and the way I specify the configuration for the apps I test. I have several collections of test suites where each collection of test suites has a ct_hook module to set up some things.
The way I configure apps I’m going to test is to call application:load/1
and then application:set_env/3
before I call application:ensure_all_started/1
.
For individual (collections) of test suites, this works well. however, when I run rebar3 ct
, it (naturally) runs multiple test suites in succession, and if I need to configure an app that I’m going to use in a later run, it is then too late to call application:set_env/3
if that app was already loaded indirectly (as a dependency – or even a dependency’s dependency) in an earlier suite’s ct_hook:
init/2
in first_ct_hook
:
% loads app_a, but also its dependency app_b and *app_b's* dependency app_z:
application:load(app_a),
application:set_env(app_a, database, my_db_config),
% …
% great success!
init/2
in second_ct_hook
:
application:load(app_b), % loads app_b (its dependency app_z is already loaded)
application:set_env(app_a, database, my_db_config),
application:set_env(app_z, important, my_important_config), % oh no! too late!
What’s the proper way to do this?