且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何模拟IQueryable< T>

更新时间:2022-02-10 14:50:44

我通常会完全按照您最终在测试中所做的来做.在编写测试时,我假设.Net库类可以正常工作,并且不包含错误,因此可以在测试中使用它们.当我需要测试列表,集合,可查询的字典等时,我只需创建真实的东西并填充测试数据即可.它使测试的可读性和编写速度更快,并且老实说,这种风险不存在.

I usually do exactly what you ended up doing in your test. When writing my tests I assume that the .Net library classes work correctly and don't contain bugs, so I can use them in the tests. When I need a test list, collection, queryable, dictionary, etc. I just create the real thing and populate with test data. It makes the tests much more readable and quicker to write, and to be honest the risk is non-existent.