我的Erlang项目由rebar管理,它分为不同的模块。
-pro
|-- rel
|-- src
|-- test
|--- module1_tests.erl
|--- module2_tests.erl
并为每个模块* _tests.erl,使用Eunit Fixtures来设置环境。例如,
module1_test_() ->
{setup,
fun setup/0,
fun clean_up/1,
fun (SetupData) ->
[
test_function(SetupData)
]
end}.
setup() ->
pro:start(),
ok.
clean_up(_) ->
pro:stop().
而Makefile是:
test:
ERL_AFLAGS="-config rel/pro/etc/app.config" $(REBAR) compile eunit skip_deps=true
这里我遇到了一个问题,因为我在test /中有很多测试模块,每个测试模块都会启动和停止整个执行流程的应用程序。有时启动应用程序会失败,告诉找不到app.config配置文件,不知道为什么。
所以我认为有没有办法在所有测试模块之前启动应用程序?
听起来像是在进行那种远离unit testing
想法的测试。也许,在这种情况下,你应该使用common test framework?
从您使用的Erlang docs -config标志(ERL_AFLAGS =“ - config rel / pro / etc / app.config”)必须是ERL_AFLAGS =“ - config app”
看看赛程:http://erlang.org/doc/apps/eunit/chapter.html#Fixtures
一种快速而肮脏的方式也可以是添加这样的东西作为第一个测试用例。
init_test() ->
{ok, Apps} = application:ensure_all_started(myapp),