初始化后,如何在烟雾测试中修复“未初始化Firebase”?

时间:2020-10-12 10:23:39

标签: firebase flutter

我正在制作Flutter应用程序,需要检查用户是否已登录以选择该应用程序的着陆页。我已经通过Firebase配置了用户登录。使用flutter run,该应用可以正常运行,但是当我运行flutter test时,测试失败,提示No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following FirebaseException was thrown building Builder(dirty):
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

test.dart

void main() {
  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    await tester.pumpWidget(MyApp());
  }
}

main.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

MyApp位于名为app.dart的文件中

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MyApp',  
      routes: {
         '/home': (context) => BottomNavigation(),  
         '/': (context) => (FirebaseAuth.instance.currentUser == null)? LoginPage():Home(),
      });
   }
}

0 个答案:

没有答案