testing - 如何使用 flutter_redux 测试 Flutter 应用程序?
问题描述
我尝试为我的 Flutter 应用程序编写第一个冒烟测试:
class MockStore extends Mock implements Store<AppState> {}
void main() {
MockStore mockStore;
setUp(() {
mockStore = MockStore();
when(mockStore.state).thenReturn(AppState.initial());
});
testWidgets('Login screen smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(App(mockStore,));
// Verify that title is shown.
expect(find.text('Sign in with google'), findsOneWidget);
});
}
但我得到:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building StoreConnector<AppState, _ViewModel>:
The method 'map' was called on null.
Receiver: null
Tried calling: map<_ViewModel>(Closure: (AppState) => _ViewModel)
如何正确模拟商店?
解决方案
您的模拟需要为 onChange getter 返回一些东西,例如:
when(mockStore.onChange).thenAnswer((_) =>
Stream.fromIterable([AppState.intial()]));
推荐阅读
- rust - 特征可以为其继承的特征的方法提供默认实现吗?
- php - SQL-如何将表B的多个ID存储到表A中?
- c# - 如何从 C# 运行 msinfo32 控制台命令?
- prestashop-1.6 - 有没有办法在不使用覆盖的情况下在模块中使用 prestashop 核心控制器?
- android - 应用内购买未登录 firebase android
- c# - 使用嵌套查询扩展时抛出多个并发操作异常
- node.js - 如何获取从一个集合到另一个集合的数据引用?蒙古数据库
- react-native - 在 ReactNative 中使用 Google 放置搜索自动完成 ..description 结果隐藏了我的屏幕组件
- reactjs - 捆绑失败:错误:找不到模块“babel-preset-react-native-stage-0/decorator-support”
- laravel - Laravel 5.6 where with If 条件