为带有 NHibernate 的存储库编写集成测试有什么意义吗?
我最近花了很多时间取出存储过程后端并将其替换为 NHiberante 基础存储库。在存储过程版本中,每个存储库进行一次测试很好,因为我可以验证我的存储过程是否有效,以及将返回的数据映射到我的对象的类是否完成了工作。
但当我用 NHibernate 启动并运行它后,我心想“这真的有必要吗?”。毕竟,NHibernate 有自己的单元测试,以确保会话知道如何进行肮脏的跟踪/映射工作等。
我在这里遗漏了一些东西,还是应该放弃这些没有实际价值的测试?
(我将在此集成测试期间使用的存储库示例)
public class UserRepository : NHibernateRepository<User>, IUserRepository
{
public UserRepository() : base()
{
}
public void DeleteUser(User User)
{
base.Delete(User);
}
public User GetUserById(int id)
{
return base.Retrieve(id);
}
public IQueryable<User> GetUserCollection()
{
return base.RetrieveAll();
}
public void SaveUser(User User)
{
base.Save(User);
}
}
I recently spent a great deal of time pulling out a stored procedure back-end and replaced it with a NHiberante base repository. One test per repository was nice in the stored procedure version because I could verify my stored procedures worked and the class that mapped the returned data to my objects did it's job.
But after I got this up and running with NHibernate I thought to myself "is this really needed?". After all, NHibernate has unit tests all its own to make sure the session knows how to do dirty tracking/mapping work/etc
Am I missing something here or should I toss these tests that offer no real value?
(sample of a repository I would exercise during this integration test)
public class UserRepository : NHibernateRepository<User>, IUserRepository
{
public UserRepository() : base()
{
}
public void DeleteUser(User User)
{
base.Delete(User);
}
public User GetUserById(int id)
{
return base.Retrieve(id);
}
public IQueryable<User> GetUserCollection()
{
return base.RetrieveAll();
}
public void SaveUser(User User)
{
base.Save(User);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至少,您应该知道您的映射正在工作。这可以通过创建一些简单的删除和保存测试来实现。
At minimum, you should know that your mapping is working. That is possible by creating some simple tests for delete and save.
您还应该放入一些 'Ghost Buster' 风格的映射测试。
You should also put in some 'Ghost Buster' style tests for your mappings.