6

So I am new in flutter and trying to perform widget testing on my app, but I am keep getting this weird error. below is my test file

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:folk_team_app/provider/auth_provider.dart';
import 'package:folk_team_app/screens/phone_login.dart';
import 'package:provider/provider.dart';

void main() async {
  TestWidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  Widget loginScreen = ChangeNotifierProvider<AuthProvider>(
      create: (context) => AuthProvider(),
      builder: (context, child) {
        return MaterialApp(
          home: PhoneLogineScreen(),
        );
      });

  testWidgets('Phone Authetication Page', (WidgetTester tester) async {
    // Build our app and trigger a frame.

    await tester.pumpWidget(loginScreen);
    await tester.pump(const Duration(seconds: 10));
    

    final titleText = find.text('Screen Title');

    // Verify that our counter starts at 0.
    expect(titleTextt, findsOneWidget);
  });
}

here is the error : enter image description here enter image description here

2
  • Please don't add screenshots, just copy logs/errors as code Commented Oct 6, 2020 at 19:12
  • You can see my answer here that solved this problem for me. Commented Nov 7, 2020 at 17:04

1 Answer 1

4

You can't directly test Firebase because it requires platform configurations in order to initialize it properly. You need to mock Firebase in the test environment using mockito.

You may find this comment and tutorial video helpful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.