unit-testing - 如何在不明确传递所有模拟类的情况下对颤振进行单元测试?
问题描述
我试图找到一种方法来模拟一个类,而无需通过 Providers 将其模拟版本作为参数显式传递。我刚开始使用 Geolocator,我想模拟它的几个功能,例如getCurrentPosition
.
到目前为止,我已经通过 Providers 传递了单例,以便在测试应用程序时可以模拟它们。但是 Geolocator 是一个静态类,当我尝试为它提供一个类型时,它会说:
The return type 'Type' isn't a 'Geolocator', as required by the closure's context.
代码如下所示:
Provider<Geolocator>(create: (context) => Geolocator)
最干净的解决方案似乎能够注入/提供该类而无需使用Provider
. 但是,我也无法通过MockGeolocator。所以我该怎么做?
解决方案
推荐阅读
- celery - 气流工作者渴望排队的任务
- asp.net - 存储过程在 ASP 页面中不起作用
- flutter - CustomPainter 使用 Listenable 重绘
- python-2.7 - 如何将两个子列表的坐标连接为对列表?
- javascript - 从 JSON 数据生成 HTML 树
- authentication - 创建跳过登录步骤的“预签名/标记化”URL(Json Web 令牌)
- adfs - ADFS 转换自定义属性
- angular - 无法以角度将样式传递给 quill-editor 组件
- c - 创建 TCP 服务器以托管 ELF 文件
- angular - 在 Angular 7 中将文件内容传递给 NGRX 效果