多主张在单元测试的构造函数? [英] Multiple assertions when unit testing constructor?

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

问题描述

我试图单元测试类2构造函数。每个构造都有设置的公共属性多个参数。我的问题是,我只有2个单元测试与多个声称要检查每个属性设置或测试各种参数,每个构造?

 公众人物(字符串名称,字符串电话,串生日)
{
   名称=名称;
   手机=手机;
   生日=生日;
}

公众人物(字符串名称):这个(姓名,NULL,NULL)
{}
 

解决方案

这是您要测试的操作,该构造函数接受__参数的值设置为正确的值。

所以我要说的每构造1测试中,有多个断言每个,以确保所有成员都设置正确。

I'm trying to unit test a class with 2 constructors. Each constructor has multiple parameters that set public properties. My question is, should I have only 2 unit tests with multiple asserts to check that each property was set OR a test for each parameter for each constructor?

Public Person(string name, string phone, string birthday)
{
   name = name;
   phone = phone;
   birthday = birthday;
}

Public Person(string name) : this(name, null, null)
{}

解决方案

The operation that you are testing is that the constructor accepts __ parameters and that the values are set to the proper value.

Therefore I would say 1 test per constructor, with multiple asserts on each, to ensure that all members are properly set.

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

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