对构造函数进行单元测试很重要吗? [英] Is it important to unit test a constructor?

查看:29
本文介绍了对构造函数进行单元测试很重要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该对构造函数进行单元测试吗?假设我有一个这样的构造函数:

Ought I to unit test constructors? Say I have a constructor like this:

IMapinfoWrapper wrapper;
public SystemInfo(IMapinfoWrapper mapinfoWrapper)
{
    this.wrapper = mapinfoWrapper;
}

我需要为此构造函数编写单元测试吗?我没有任何用于包装器变量的 getter,因此我不需要对其进行测试.

Do I need to write a unit test for this construtor? I don't have any getters for the wrapper variable, so I don't need to test that.

推荐答案

单元测试是关于测试对象的公共状态、行为和交互.

Unit testing is about testing the public states, behaviors, and interactions of your objects.

如果你只是在你的构造函数中设置了一个私有字段,还有什么要测试的?

If you simply set a private field in your constructor, what is there to test?

不要费心对简单的访问器和修改器进行单元测试.这太愚蠢了,对任何人都没有帮助.

Don't bother unit-testing your simple accessors and mutators. That's just silly, and it doesn't help anyone.

这篇关于对构造函数进行单元测试很重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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