调用 createUserWithEmailAndPassword 后 Firebase Emulator Suite 没有响应
no response from Firebase Emulator Suite after calling createUserWithEmailAndPassword
如果我尝试使用 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 工具
我的浓缩咖啡测试代码如下:
@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 9.0(API 级别 28)或更高版本上进行测试,请注意在网络安全配置 (https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted) 中允许明文流量。
如果我尝试使用 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 工具我的浓缩咖啡测试代码如下:
@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 9.0(API 级别 28)或更高版本上进行测试,请注意在网络安全配置 (https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted) 中允许明文流量。