【发布时间】:2014-09-29 07:56:14
【问题描述】:
我正在尝试编写一个单元测试,它将针对从方法返回的字符串执行检查。该字符串是实体的一部分,应该通过调用数据库来生成。我可以轻松地存根此类实体,但我不知道如何省略对数据库的调用,因为它是方法的一部分。
方法如下:
private string GetDescriptionForRelationEntry(string relAttrId, string client)
{
// here we are querying the database
var relationEntities = new EntityDatabaseQuery<AttributeEntryEntity>();
// the rest of the method
}
需要执行指定为the rest of the method 的部分,因为我必须获取字符串结果才能执行必要的检查。所以,基本上,我只需要“伪造”一行代码。
现在我不能说允许对 SUT 类进行多广泛的修改,因此我不会将此问题限制为任何特定的解决方案。任何帮助将不胜感激。
【问题讨论】:
标签: c# database unit-testing