我正在测试函数的返回值.两者中哪一个是首选方式?
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带行号也应该足够了.