【问题标题】:no response from Firebase Emulator Suite after calling createUserWithEmailAndPassword调用 createUserWithEmailAndPassword 后 Firebase Emulator Suite 没有响应
【发布时间】:2021-02-22 22:05:18
【问题描述】:

如果我尝试使用 Firebase Emulator Suite 在 espresso 测试用例中使用 createUserWithEmailAndPassword(emai, password) 创建一个新用户,则不会发生任何事情。相同的代码适用于实时 Firebase 实例。日志什么也没显示。

我正在尝试使用 Firebase Emulator Suite 来测试我的应用。模拟器正确启动。日志显示:

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://localhost:4000                │
└─────────────────────────────────────────────────────────────┘

┌────────────────┬──────────────────────────────────┬─────────────────────────────────┐
│ Emulator       │ Host:Port                        │ View in Emulator UI             │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Authentication │ localhost:9099                   │ http://localhost:4000/auth      │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Functions      │ localhost:5001                   │ http://localhost:4000/functions │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Firestore      │ localhost:8080                   │ http://localhost:4000/firestore │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Database       │ localhost:9000                   │ http://localhost:4000/database  │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Hosting        │ Failed to initialize (see above) │                                 │
├────────────────┼──────────────────────────────────┼─────────────────────────────────┤
│ Pub/Sub        │ localhost:8085                   │ n/a                             │
└────────────────┴──────────────────────────────────┴─────────────────────────────────┘
  Emulator Hub running at localhost:4400
  Other reserved ports: 4500

模拟器 UI 也可以正常工作。我正在使用 9.4.0 版中的 Firebase 工具

我的 espresso 测试代码如下:

    @Test
    fun registerAndSigningInWithVeryNewUser() {
        val auth = Firebase.auth
        auth.useEmulator("10.0.2.2", 9099) // like https://firebase.google.com/docs/emulator-suite/connect_auth#android_ios_and_web_sdks
        // sign out at first to ensure that accidentally no other user is logged in
        auth.signOut()
        // and now creating new user
        auth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener { task ->
                    if (task.isSuccessful) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "registerAndSigningInWithVeryNewUser: creating new user success")
                        val user = auth.currentUser
                    } else {
                        // If sign in fails
                        Log.w(TAG, "registerAndSigningInWithVeryNewUser: creating new user failure", task.exception)
                        assert(false)
                    }
                }
        Thread.sleep(10000)

        val user = auth.currentUser
        Log.d(TAG, "registerAndSigningInWithVeryNewUser: User = $user")
    }

我认为原因是异步函数调用,尽管我添加了丑陋的 Thread.sleep(10000) 语句。但没有效果。

如果我在模拟器 UI 中手动创建用户并尝试使用 signInWithEmailAndPassword(email, password) 登录,也会发生同样的情况(什么都没有)

有什么想法吗?

【问题讨论】:

    标签: android kotlin firebase-authentication android-espresso firebase-tools


    【解决方案1】:

    问题是,我试图从真实的硬件设备上运行测试用例。它可以在虚拟设备中工作。

    但如果您在 Android 9.0(API 级别 28)或更高版本上进行测试,请注意在网络安全配置 (https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted) 中允许明文流量。

    【讨论】:

      猜你喜欢
      • 2020-02-12
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多