如何在Flutter Integration测试中模拟/绕过外部依赖关系和工作流程?

时间:2019-05-09 07:29:52

标签: dart flutter flutter-test

我正在编写Flutter应用,该应用仅具有基于firebase_authgoogle_sign_in的Google登录。我找不到如何在Flutter中模拟依赖项或如何单击Google身份验证对话框或绕过整个身份验证工作流程的标准工作示例。

我正在使用flutter_driver来编写集成测试,如下所述。

Google_Sign_In

app_test.dart

import 'package:flutter_driver/driver_extension.dart';
import 'package:pruoo_app/main.dart' as app;

void main() {
  enableFlutterDriverExtension();
  app.main();
}

login.dart

//...imports

class LoginView extends StatefulWidget {
  @override
  _LoginViewState createState() => _LoginViewState();
}

class _LoginViewState extends State<LoginView> {
  StreamSubscription<AuthenticationState> x;

  void getStream(AuthenticationState state, BuildContext context) async {
    if (state.toString() == 'AuthenticationAuthenticated') {
      print("Navigate to Main Page");
      );
  }
}

  Widget build(BuildContext context) {
    final AuthenticationBloc authenticationBloc =
        BlocProvider.of<AuthenticationBloc>(context);

    x = authenticationBloc.state.listen((state) {
      getStream(state, context);
    });

    return Scaffold(
        body: Center(
            child: GoogleSignInButton(
          onPressed: () {
            authenticationBloc.dispatch(LoggedIn());
          },
        )));
  }
}

0 个答案:

没有答案