由网友(大气的昵称)分享简介:我试图单元测试类2构造函数。每个构造都有设置的公共属性多个参数。我的问题是,我只有2个单元测试与多个声称要检查每个属性设置或测试各种参数,每个构造?公众人物(字符串名称,字符串电话,串生日){名称=名称;手机=手机;生日=生日;}公众人物(字符串名称):这个(姓名,NULL,NULL){}解决方案 这是您要测试的...![第4章一次函数 单元测试 A卷](https://p.xsw88.cn/allimgs/daicuo/20230904/8780.png)
我试图单元测试类2构造函数。每个构造都有设置的公共属性多个参数。我的问题是,我只有2个单元测试与多个声称要检查每个属性设置或测试各种参数,每个构造?
公众人物(字符串名称,字符串电话,串生日)
{
名称=名称;
手机=手机;
生日=生日;
}
公众人物(字符串名称):这个(姓名,NULL,NULL)
{}
解决方案
这是您要测试的操作,该构造函数接受__参数的值设置为正确的值。
所以我要说的每构造1测试中,有多个断言每个,以确保所有成员都设置正确。
![第4章一次函数 单元测试 A卷](https://p.xsw88.cn/allimgs/daicuo/20230904/8780.png)
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.
相关推荐
最新文章