简体   繁体   English

Flutter 集成测试 firebase 身份验证(电子邮件链接或谷歌登录)

[英]Flutter integration test firebase auth (email link or google sign in)

I'm adding integration testing (using the integration_test package) to my app but I am running into a problem.我正在向我的应用程序添加集成测试(使用 integration_test 包),但我遇到了问题。

Let me explain.让我解释。 The first step when my app launch is authentication for which I have 3 options: firebase email link, firebase google sign in, and firebase facebook sign in.我的应用程序启动时的第一步是身份验证,我有 3 个选项:firebase email 链接、firebase 谷歌登录和 firebase facebook 登录。

What is blocking me is that all these sign in methods require actions outside of the main app dart code and thus are not accessible by flutter driver.阻碍我的是,所有这些登录方法都需要在主应用程序 dart 代码之外执行操作,因此 flutter 驱动程序无法访问。

Am I missing something here?我在这里错过了什么吗? And if not how should that case be handled?如果不是,应该如何处理该案例?

Cheers!干杯!

You can use Patrol – it lets you interact with native system UI from within your Flutter integration tests.您可以使用Patrol——它可以让您在 Flutter 集成测试中与本机系统 UI 进行交互。 Example:例子:

import 'package:flutter_test/flutter_test.dart';
import 'package:patrol/patrol.dart';

void main() {
  patrolTest(
  'signs in', 
  nativeAutomation: true,
  (PatrolTester $) async {
    await $.native.enterText(
      Selector(textContains: 'Email'),
      text: 'tester@awesomeapp.pl'),
    );
    await $.native.enterText(
      Selector(textContains: 'Password'),
      text: 'ny4ncat'),
    );
    await $.native.tap(Selector(text: 'Continue'));

     // you should be signed in
  });
}

You can add the fourth way of signing in - using username and password.您可以添加第四种登录方式 - 使用用户名和密码。 Firebase should support this kind of very common situation, so you can do it within lines of code. Firebase 应该支持这种非常常见的情况,所以你可以在几行代码内完成。

If you do not want the end users to login by password, you can simply disable this method in production build and only enable it in debug build.如果您不希望最终用户通过密码登录,您可以简单地在生产构建中禁用此方法,仅在调试构建中启用它。

Another way is to mock your authentication system.另一种方法是模拟您的身份验证系统。 In other words, when doing testing, you have a button called "fake sign in", and your integration test driver just click that button.换句话说,在进行测试时,您有一个名为“假登录”的按钮,您的集成测试驱动程序只需单击该按钮。

To make the test less flaky i would recommend to not rely on an internet connection or a third party (like Firebase or Google login).为了使测试不那么不稳定,我建议不要依赖互联网连接或第三方(如 Firebase 或 Google 登录)。

I would advise to use a Mock for this.我建议为此使用 Mock 。 So when you try to login to your test you send a fake response, and in that way you can continue using the app.因此,当您尝试登录测试时,您会发送虚假响应,这样您就可以继续使用该应用程序。

The following article explains how to use a mock: https://medium.com/stuart-engineering/mocking-integration-tests-with-flutter-af3b6ba846c7以下文章解释了如何使用模拟: https://medium.com/stuart-engineering/mocking-integration-tests-with-flutter-af3b6ba846c7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM