Reputation: 13632
I have an Erlang application that is a REST service. I have a relx file and when I launch:
rebar3 release
I get an executable
./_build/default/rel/myapp/bin/myapp
When I launch that, the service starts and I can hit my service on localhost:80
.
Now I'm trying to write a test suite to test some API calls. In my common test init_per_suite(Config)
function, I want to launch my app, something like:
-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.
What is the proper way to launch my release from this common_test suite and do this testing?
BTW I am launching my tests using
rebar3 ct
Upvotes: 2
Views: 689
Reputation: 43
I had the same problem. You method can start the application but can't load the sys.config file. If the application depends on some configuration in this file, it will be started fail.
Upvotes: 1
Reputation: 13632
OK, I figured out a way to do this (not sure if it is the best way):
init_per_suite(Config) ->
{ok, _} = application:ensure_all_started(myapp),
[].
%tests that hit localhost:port..
end_per_suite(Config) ->
ok = application:stop(myapp).
Upvotes: 2