小编car*_*arp的帖子

没有断言/反驳的ExUnit,完全依赖于模式匹配?

我正在测试函数的返回值.两者中哪一个是首选方式?

test "extra verbose, using assert" do
  {:error, reason} = MyModule.my_fun
  assert reason == :nope
end

test "using pattern matching only" do
  {:error, :nope} = MyModule.my_fun
end
Run Code Online (Sandbox Code Playgroud)

我喜欢第一个,因为我现在不需要测试需要一个assert语句,运行测试时的错误信息更具描述性.Otoh,MatchError带行号也应该足够了.

testing elixir ex-unit

6
推荐指数
1
解决办法
1939
查看次数

标签 统计

elixir ×1

ex-unit ×1

testing ×1