[erlang-questions] How to start application before all eunit cases

Tuncer Ayaz <>
Tue Nov 25 13:45:37 CET 2014


On Mon, Nov 24, 2014 at 8:06 AM, linbo liao wrote:
> My Erlang project managed by rebar, it divides to different module.
>
> -pro
>   |-- rel
>   |-- src
>      |--- module1
>      |--- module2
>   |-- test
>      |--- module1_tests.erl
>      |--- module2_tests.erl
>
> and for each module*_tests.erl, Use Eunit Fixtures to setup
> environment. For example,
>
> module1_test_() ->
>     {setup,
>         fun setup/0,
>         fun clean_up/1,
>         fun (SetupData) ->
>             [
>                 test_function(SetupData)
>             ]
>     end}.
>
> setup() ->
>     pro:start(),
>     ok.
>
> clean_up(_) ->
>     pro:stop().
>
> And Makefile is:
>
> test:
>     ERL_AFLAGS="-config rel/pro/etc/app.config"  $(REBAR)  compile eunit
> skip_deps=true
>
> Here I encounter a problem, since I have many test module in test/,
> each test module will start and stop application for whole executing
> flow. Sometimes start application will be failed, told not find
> app.config configure file, not sure why.
>
> So I think is there a way to start application before all test
> module?

Without a complete project to check out, like Nathan, I also cannot
answer why the config file is sometimes not found. However, there is a
rebar hook solution you can use:

$ cat pro/rebar.config:
{plugins, [pro_eunit_hook]}.
...


$ cat pro/pro_eunit_hook.erl:
-module(pro_eunit_hook).
-export([pre_eunit/2]).
pre_eunit(_, _) ->
    %% if not already started, start the application
    <code to start your app(s)>
    ok.


More information about the erlang-questions mailing list