erlang自带的common test框架用作测试比较方便,支持分布式测试等强大功能,个人感觉美中不足之处是把用例和测试库没有很好分离。当然可以自己封装测试库import使用,不过总觉得不够简洁。
下面记录一下基本使用方法,主要利用erlang强大的模式匹配
编写脚本basic/basic_SUITE.erl如下:
-module(basic_SUITE). %% %% highly recommended you add the line below which may %% provide some macro -include_lib("common_test/include/ct.hrl"). -export([all/0]). -export([test1/1, test2/1, test_http/1]). all() -> [test1,test2,test_http]. test1(_Config) -> 1 = 1. test2(_Config) -> A = 0, 1/A. test_http(_Config) -> inets:start(), {ok, { {Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request(get, {"http://api.dbank.com/rest.php", []}, [], []), io:format("~p~n",[Version]), io:format("~p~n",[ReasonPhrase]), io:format("~p~n",[Headers]),