如何在所有eunit案例之前启动应用程序

问题描述 投票:0回答:3

我的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配置文件,不知道为什么。

所以我认为有没有办法在所有测试模块之前启动应用程序?

erlang otp rebar eunit
3个回答
1
投票

听起来像是在进行那种远离unit testing想法的测试。也许,在这种情况下,你应该使用common test framework


1
投票

从您使用的Erlang docs -config标志(ERL_AFLAGS =“ - config rel / pro / etc / app.config”)必须是ERL_AFLAGS =“ - config app”


0
投票

看看赛程:http://erlang.org/doc/apps/eunit/chapter.html#Fixtures

一种快速而肮脏的方式也可以是添加这样的东西作为第一个测试用例。

init_test() ->
  {ok, Apps} = application:ensure_all_started(myapp),
© www.soinside.com 2019 - 2024. All rights reserved.