我尝试为我的 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)
如何正确模拟商店?