testing - 如何使用 flutter_redux 测试 Flutter 应用程序?

标签 testing redux flutter flutter-test flutter-redux

我尝试为我的 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()]));

关于testing - 如何使用 flutter_redux 测试 Flutter 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54780916/

相关文章:

javascript - React-Redux : Assigning a modified array to a property in the state

linux - 什么是单元测试?以及如何为 Linux C 程序制作一个?

testing - 如何计算假设检验中的 p 值(线性回归)

testing - 通过命令行向 NUnit 传递参数

javascript - Redux - 尝试向configureStore添加功能

react-native - react 导航和 Redux : All screens rerender using a StackNavigator when redux state is changed

flutter - Riverpod 作为全局变量

android - 找不到builder.jar(com.android.tools.build:builder:3.5.3)

flutter - flutter shared_preferences 有多大算太大?

java - 验证 Java 中的对象删除