1

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?

linbo
  • 2,393
  • 3
  • 22
  • 45

3 Answers3

1

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

Viacheslav Kovalev
  • 1,745
  • 12
  • 17
1

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

Alexei K
  • 142
  • 1
  • 5
1

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),
Albin Stigo
  • 2,082
  • 2
  • 17
  • 14