【发布时间】:2017-04-12 16:56:13
【问题描述】:
我正在测试一个函数的返回值。两者中哪一个是首选方式?
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
我喜欢第一个,因为我现在不喜欢,测试需要assert 语句,并且运行测试时的错误消息更具描述性。 Otoh,带有行号的MatchError 也应该足够了。
【问题讨论】: