How to start application before all eunit cases

864 views Asked by At

My Erlang project managed by rebar, it divides to different module.

-pro
  |-- rel
  |-- src
  |-- 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?

3

There are 3 answers

0
Alexei K On

From Erlang docs -config flag you used (ERL_AFLAGS="-config rel/pro/etc/app.config") has to be ERL_AFLAGS="-config app"

0
Viacheslav Kovalev On

Sounds like you performing kind of testing that far away from unit testing idea. Maybe, in this case, you should use common test framework?

0
Albin Stigo On

Look at Fixtures: http://erlang.org/doc/apps/eunit/chapter.html#Fixtures

A quick and dirty way could also be to add something like this as the first test case.

init_test() ->
  {ok, Apps} = application:ensure_all_started(myapp),