Unit testing OCaml OUnit支架示例:设置和拆卸
我真的不知道如何使用支架设置和拆除与它(版本2)。 有人想提供一个完整的例子吗 以下是Unit testing OCaml OUnit支架示例:设置和拆卸,unit-testing,ocaml,Unit Testing,Ocaml,我真的不知道如何使用支架设置和拆除与它(版本2)。 有人想提供一个完整的例子吗 以下是OUnit2.括号功能文档: val bracket : (test_ctxt -> 'a) -> ('a -> test_ctxt -> unit) -> test_ctxt -> 'a bracket set_up tear_down test_ctxt set up an object and register it to be tore down i
OUnit2.括号
功能文档:
val bracket : (test_ctxt -> 'a) ->
('a -> test_ctxt -> unit) -> test_ctxt -> 'a
bracket set_up tear_down test_ctxt set up an object
and register it to be tore down in test_ctxt.
您可以按如下方式设置测试套件:
let test_suite =
"suite" >::: [
"test1" >:: test1_fun
]
let _ =
run_test_tt_main test_suite
然后像这样运行它:
let test_suite =
"suite" >::: [
"test1" >:: test1_fun
]
let _ =
run_test_tt_main test_suite
在此工作流中,我应该将括号放在哪里
链接到
文件
test\u stack.ml
位于ounit-2.0.0/examples
测试括号中,适用于ounit版本1,因此该文件没有用处。好的,查看此文件后获取:
此示例将在每次测试后作为一个拆卸函数系统地销毁哈希表
open ListLabels (* map with label *)
let test_sentence test_ctxt =
assert_equal "Foo" "Foo"
(** In my case, clear a hashtable after each test *)
let tear_down () test_ctxt =
Hashtbl.clear Globals.flags_tbl
(** List of test cases as (name, function) tuples *)
let test_list = [
"sentence", test_sentence;
]
(** Test suite for all tags *)
let tag_test_suite =
"tags" >::: (map test_list ~f:(fun (name, test_fn) ->
name >:: (fun test_ctxt ->
bracket ignore tear_down test_ctxt;
test_fn test_ctxt
)
))