我有一個基於牛仔的Erlang應用程序,我想測試它。基於牛仔使用常見測試測試Erlang應用程序
以前我使用wooga的庫etest_http來完成這類任務,但是我想開始使用通用測試,因爲我注意到這是牛仔中使用的方式。我試圖設置一個非常基本的測試,但我無法正確運行它。
任何人都可以提供一個示例來測試基本示例echo_get並告訴我使用示例中包含的Makefile從控制檯運行測試的正確方法是什麼?
我有一個基於牛仔的Erlang應用程序,我想測試它。基於牛仔使用常見測試測試Erlang應用程序
以前我使用wooga的庫etest_http來完成這類任務,但是我想開始使用通用測試,因爲我注意到這是牛仔中使用的方式。我試圖設置一個非常基本的測試,但我無法正確運行它。
任何人都可以提供一個示例來測試基本示例echo_get並告訴我使用示例中包含的Makefile從控制檯運行測試的正確方法是什麼?
該示例僅適用於構建echo_get應用程序。因此,要測試echo_get應用程序,您可以添加測試套件並從shell中調用make && rebar -v 1 skip_deps=true ct
(鋼筋應位於PATH中)。 另外您還需要在您的Erlang PATH中使用etest和etest_http,或者在您的應用程序中將它與rebar.config一起添加。您可以使用httpc或OS捲曲:在cmd/1,而不是ehttp_test :)
測試/ my_test_SUITE.erl(full example)
-module(my_test_SUITE).
-compile(export_all).
-include_lib("common_test/include/ct.hrl").
% etest macros
-include_lib ("etest/include/etest.hrl").
% etest_http macros
-include_lib ("etest_http/include/etest_http.hrl").
suite() ->
[{timetrap,{seconds,30}}].
init_per_suite(Config) ->
%% start your app or release here
%% for example start echo_get release
os:cmd("./_rel/bin/echo_get_example start"),
Config.
end_per_suite(_Config) ->
%% stop your app or release here
%% for example stop echo_get release
os:cmd("./_rel/bin/echo_get_example stop")
ok.
init_per_testcase(_TestCase, Config) ->
Config.
end_per_testcase(_TestCase, _Config) ->
ok.
all() ->
[my_test_case].
my_test_case(_Config) ->
Response = ?perform_get("http://localhost:8080/?echo=saymyname"),
?assert_status(200, Response),
?assert_body("saymyname", Response).
ok.
由於某些原因,發佈不是未開始的。我試圖更改爲os:cmd(「../../_ rel/bin/echo_get_example [start或stop]」)的路徑,但它也不起作用。通過運行在不同的shell中釋放並運行它的測試(甚至停止命令)。任何想法? – user601836
這是什麼意思 - 釋放沒有啓動?一些shell輸出或日誌將對您有所幫助。 – sysoff
我的意思是,所有的測試失敗,因爲服務器沒有運行。我可以通過放置一個計時器來解決它:OS:cmd/1命令之後的睡眠(1000)...但我相信這不是正確的方法。 – user601836
下啓動程序hello_world應用程序及其相關性,但使用最近編譯版本而不是./_rel中的版本;這可能是也可能不是你想要的,但它避免了timer:sleep(1000)
-module(hello_world_SUITE).
-include_lib("common_test/include/ct.hrl").
-export([all/0, init_per_suite/1, end_per_suite/1]).
-export([http_get_hello_world/1]).
all() ->
[http_get_hello_world].
init_per_suite(Config) ->
{ok, App_Start_List} = start([hello_world]),
inets:start(),
[{app_start_list, App_Start_List}|Config].
end_per_suite(Config) ->
inets:stop(),
stop(?config(app_start_list, Config)),
Config.
http_get_hello_world(_Config) ->
{ok, {{_Version, 200, _ReasonPhrase}, _Headers, Body}} =
httpc:request(get, {"http://localhost:8080", []}, [], []),
Body = "Hello World!\n".
start(Apps) ->
{ok, do_start(_To_start = Apps, _Started = [])}.
do_start([], Started) ->
Started;
do_start([App|Apps], Started) ->
case application:start(App) of
ok ->
do_start(Apps, [App|Started]);
{error, {not_started, Dep}} ->
do_start([Dep|[App|Apps]], Started)
end.
stop(Apps) ->
_ = [ application:stop(App) || App <- Apps ],
ok.
使用https://github.com/extend/gun
到(在「用戶」文件夾中考慮「槍」)運行所提供的例子: ct_run -suite twitter_SUITE.erl -logdir ./results -pa /home/user/gun/deps/*/ebin /home/user/gun/ebin
echo_get不包含任何常見的測試套件。 Makefile也沒有運行通用測試套件的部分。所以如果你想用ct來測試它,你必須實現一個測試套件。要運行套件,您可以使用標準的erlang實用程序ct_run,或者您可以嘗試使用rebar(https://github.com/basho/rebar)。 –
我知道echo_get不包含任何測試。我在問例子。 – user601836