unit-testing - 无法对 cloud_firestore 进行实时单元测试
问题描述
我目前正在尝试编写一个单元测试来验证是否存在一定数量的文档。
这是我到目前为止所拥有的
test('Login with no account', () async {
Firestore _firestore = Firestore.instance;
final QuerySnapshot result = await _firestore
.collection(UserFirestoreField.Collection)
.where(UserFirestoreField.EmailAddress, isEqualTo: 'email@example.com')
.where(UserFirestoreField.Password, isEqualTo: 'wrongpassword')
.getDocuments();
final List<DocumentSnapshot> docs = result.documents;
print(docs);
});
我得到的错误是
包:flutter/src/services/platform_channel.dart 314:7 MethodChannel.invokeMethod
MissingPluginException(在通道 plugins.flutter.io/cloud_firestore 上找不到方法 Query#getDocuments 的实现)
我的 android 模拟器在我的应用程序启动时运行。
我见过的每个指南都在谈论模拟数据库,我想实际检查真实的数据库。
有什么方法可以在飞镖/颤振中做到这一点?
谢谢!
解决方案
在 Flutter 中,单元和小部件测试在您的主机上运行,该主机没有您的 firebase 插件的本机部分。这就是您收到此错误的原因。
您确实应该在测试中模拟数据库,但如果您真的想测试您的应用程序,使其接近用户运行的方式,您将在模拟器上运行集成测试。
您还可以使用基于 dart 的 Firebase 插件或使用 Firebase REST API。
您可以在此处找到更多相关信息:https ://flutter.dev/docs/testing
推荐阅读
- python - 在 MSAL Python 库中,ConfidentialClientApplication 及其底层 TokenCache 对象是线程安全的吗?
- javascript - Javascript 在渲染代码之前从 DOM 中删除项目
- reactjs - React:在使用上下文提供程序之前在上下文提供程序中运行异步操作
- flutter - 如何使用 SpeedDial 制作工作按钮?
- java - 动态地希望从管理员端更新编辑文本中的文本,并应在用户端反映更新的文本
- django - 在 django 中设置排序以使用特定于语言的顺序
- caching - touch(): Utime failed: 缓存清除权限被拒绝
- postgresql - HQL - 检查数组是否包含值
- javascript - 如何更改材质ui图标的大小和颜色?
- javascript - Firebase 异步/等待查询未按预期工作