Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 10 years ago.
这些函数通常会提供更有用的输出。例如,assertEquals 测试可以告诉您预期值和实际值,以及它们不相等。
assertEquals
例如,以下代码:
this->assertEquals(1, 0);
将产生以下输出:
Failed asserting that 0 matches expected 1.
These functions usually give more useful output. For example, an assertEquals test could tell you the expected and actual values, and that they were not equal.
For example, the following code:
Will produce this output:
这也与冗长有关。这:
this->assert(foo == array_pop(stack));
比以下内容简洁得多:
this->assertEqual(foo, array_pop(stack));
或者甚至更好:
$popped_value = array_pop(stack); this->assertEqual($popped_value, foo);
在其他框架(例如 .NET 的 NUnit)中,它甚至更好:
Assert.AreEqual(stack.Pop(), foo);
vs
var poppedValue = stack.Pop(); Assert.That(poppedValue, Is.EqualTo(foo));
阅读最后一个示例几乎就像有人在解释代码你。当您处理旧的/其他人的代码时,这是非常宝贵的。
It's also about verbosity. This:
Is much less verbose than:
Or even better:
In other frameworks (such as .NET's NUnit), it gets even better:
Reading the last example is almost as if somebody was explaining the code to you. That's invaluable when you deal with old/somebody's else code.
原因是能够为失败的测试提供更清晰的消息,例如比较;
Test failed: 'foo' == array_pop(stack) assertion failed
到
Test failed: foo should be 2, actual value 5.
The reason is afaik to be able to present cleaner messages for failing tests, compare for example;
to
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(3)
这些函数通常会提供更有用的输出。例如,
assertEquals
测试可以告诉您预期值和实际值,以及它们不相等。例如,以下代码:
将产生以下输出:
These functions usually give more useful output. For example, an
assertEquals
test could tell you the expected and actual values, and that they were not equal.For example, the following code:
Will produce this output:
这也与冗长有关。这:
比以下内容简洁得多:
或者甚至更好:
在其他框架(例如 .NET 的 NUnit)中,它甚至更好:
vs
阅读最后一个示例几乎就像有人在解释代码你。当您处理旧的/其他人的代码时,这是非常宝贵的。
It's also about verbosity. This:
Is much less verbose than:
Or even better:
In other frameworks (such as .NET's NUnit), it gets even better:
vs
Reading the last example is almost as if somebody was explaining the code to you. That's invaluable when you deal with old/somebody's else code.
原因是能够为失败的测试提供更清晰的消息,例如比较;
到
The reason is afaik to be able to present cleaner messages for failing tests, compare for example;
to