单元测试IQueryable [英] Unit Test IQueryable

查看:136
本文介绍了单元测试IQueryable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为一个需要IQueryable集合的方法写一个单元测试。



如何在我的单元测试中实例化集合,测试方法?这是我的测试中的默认代码

  IQueryable< Item> Items = null; // TODO:初始化一个合适的值

这里是我尝试写的

  IQueryable< Item> Items = new IQueryable< Item> ;; // TODO:初始化到一个合适的值

你可以使用 .AsQueryable()对任何类型的集合/列表/数组,但是由于不同的查询提供程序支持不同的选项/方法,因此您 不能 对此进行单元测试。你只能进行集成测试。任何单元测试(尤其是使用对象的单元测试)对您的系统没有任何帮助。


I am trying to write a unit test for a method which takes an IQueryable collection.

How should I instantiate the collection in my unit test before I pass it to the method for test? This is the default code in my test

IQueryable<Item> Items = null; // TODO: Initialize to an appropriate value

And here is what I tried writing

IQueryable<Item> Items = new IQueryable<Item>; // TODO: Initialize to an appropriate value

Am I making a school boy error?

解决方案

Well, you can use .AsQueryable() on any typed collection/list/array, however IMO you cannot unit test this, as different query providers support different options/methods. You can only integration-test this. Any unit test (especially one using objects) does little or nothing to prove your system.

这篇关于单元测试IQueryable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆