【问题标题】:Erlang; launch application at the start of common test二郎;在通用测试开始时启动应用程序
【发布时间】:2019-10-17 16:06:44
【问题描述】:

我有一个 REST 服务的 Erlang 应用程序。我有一个 relx 文件,当我启动时:

rebar3 release

我得到一个可执行文件

./_build/default/rel/myapp/bin/myapp

当我启动它时,服务就会启动,我可以在localhost:80 上点击我的服务。

现在我正在尝试编写一个测试套件来测试一些 API 调用。在我的常见测试init_per_suite(Config) 函数中,我想启动我的应用程序,例如:

-module(apitest_SUITE).
-include_lib("common_test/include/ct.hrl").
-export([all/0]).
-export([test1/1, init_per_suite/1, end_per_suite/1]).

all() -> [test1].

init_per_suite(Config) ->
    %LAUNCH MY APP HERE!!!
    %LAUNCHING ../../_build/default/rel/myapp/bin/myapp SEEMS WRONG TO ME
    [].

end_per_suite(Config) ->
    %KILL MY APP HERE!!!
    ok.

test1(Config) ->
    httpc:get("localhost:80"). %e.g.

从这个 common_test 套件启动我的版本并进行测试的正确方法是什么?

顺便说一句,我正在使用

启动我的测试
rebar3 ct

【问题讨论】:

    标签: erlang


    【解决方案1】:

    好的,我想出了一个办法(不确定是不是最好的办法):

    init_per_suite(Config) ->
        {ok, _} = application:ensure_all_started(myapp),
        [].
    
    %tests that hit localhost:port..
    
    end_per_suite(Config) ->
        ok = application:stop(myapp).
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。您的方法可以启动应用程序,但无法加载 sys.config 文件。如果应用程序依赖于该文件中的某些配置,则会启动失败。

      【讨论】:

        猜你喜欢
        • 2017-09-22
        • 2011-09-08
        • 1970-01-01
        • 2015-03-02
        • 1970-01-01
        • 2012-06-16
        • 1970-01-01
        • 2011-07-19
        • 1970-01-01
        相关资源
        最近更新 更多