【发布时间】:2011-05-10 21:38:25
【问题描述】:
我有一个对象在构造函数中接受相同类型的参数:
public class Person {
private Person theParent;
private string theName;
public Person(string aName, Person aParent)
{
if(aParent == null)
{
thrown new ArgumentNullException("aParent");
}
theParent = aParent;
theName = aName;
}
}
在我的单元测试中,我必须创建一个新的 Person 对象,但构造函数需要传入另一个 Person 对象。我通过从数据库(使用 NHibernate 及其所有魔法)*。我不想将数据库访问绑定到此测试中,因为它没有测试任何数据库功能。我应该只模拟父对象(我在其他一些测试中使用 Rhino Mocks)还是有更好的方法来解决这个问题?
*保证数据库中始终有一条记录可以检索以创建父对象。
【问题讨论】:
标签: c# unit-testing rhino-mocks