为什么单元测试系统包括无用的断言方法? [英] Why do Unit Test systems include useless assertive methods?

查看:204
本文介绍了为什么单元测试系统包括无用的断言方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么像 PHPUnit包含似乎是重复的运算符,这些运算符只会增加单元测试的开销。我可以理解其中的一些方法,但是大多数方法似乎都在浪费时间。

I'm wondering why unittest systems like PHPUnit include what seems to be repetitive operators that just add overhead to the unit tests. I can understand a couple of those methods, but most seem like a total waste of time.

public function testPop(array stack)
{
    this->assertEquals('foo', array_pop(stack));
    this->assertEmpty(stack);
}

vs原始代码(更短,更快)

vs raw code (which is shorter and faster)

public function testPop(array stack)
{
    this->assert('foo' == array_pop(stack));
    this->assert(empty(stack));
}

这里提供这些方法是为了让那些不懂他们所用语言的人仍然可以编写单元测试的程序吗?我确信这个项目的作者比我自己聪明,所以一定有原因。

Are these methods here for just so people that don't understand the language they are programming in can still write unit-tests? I'm sure the authors of this projects are smarter than myself so there must be a reason.

推荐答案

这些函数通常会提供更多功能有用的输出。例如, 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.

例如,以下代码:

this->assertEquals(1, 0);

将产生以下输出:

Failed asserting that 0 matches expected 1.

这篇关于为什么单元测试系统包括无用的断言方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆