gpt4 book ai didi

erlang - 使用普通测试基于 cowboy 测试 Erlang 应用程序

转载 作者:行者123 更新时间:2023-12-04 02:42:24 32 4
gpt4 key购买 nike

我有一个基于 Cowboy 的 Erlang 应用程序,我想测试它。

之前我用的是wooga的库etest_http对于此类任务,但我想开始使用通用测试,因为我注意到这是 cowboy 中使用的方式。我试图设置一个非常基本的测试,但我无法正确运行它。

任何人都可以为我提供一个样本来测试基本示例 echo_get并告诉我使用示例中包含的 Makefile 从控制台运行测试的正确方法是什么?

最佳答案

示例 make 仅用于构建 echo_get 应用程序。因此,要测试 echo_get 应用程序,您可以添加测试套件并从 shell 调用 make && rebar -v 1 skip_deps=true ct(rebar 应该在 PATH 中)。您还需要在您的 Erlang PATH 中使用 etest 和 etest_http,或者在您的应用程序中使用 rebar.config 添加它。您可以将 httpc 或 curl 与 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.

关于erlang - 使用普通测试基于 cowboy 测试 Erlang 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19608156/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com