Search packages, repositories and app categories

Package detailsv0.4.2

google_sign_in_mocks

Mocks for Google Sign In. Use this package with `firebase_auth_mocks` to write unit tests involving Firebase Authentication.

AndroidiOSWebmacOS
30-day downloads
17K
Likes
35
Pub points
150

Install package

flutter pub add google_sign_in_mocks

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A testing package that provides mock implementations for Google Sign In, enabling developers to simulate authentication flows without requiring actual Google accounts. It integrates seamlessly with firebase_auth_mocks, making it ideal for writing reliable unit tests for Firebase Authentication logic in Flutter apps. The mocks support all major platforms including Android, iOS, Web, and macOS, ensuring consistent test behavior across environments.

Use cases

  • Unit testing Firebase Auth with Google Sign In
  • Simulating login/logout flows in tests
  • Testing app behavior after Google Sign In
  • Validating state changes triggered by authentication
  • Ensuring platform-agnostic test reliability

Key features

  • Mock GoogleSignIn class with configurable responses
  • Integration with firebase_auth_mocks
  • Supports all major platforms
  • Easy setup for test environments
  • No external dependencies during testing

Suitable for

  • Flutter developers writing unit tests
  • Teams using Firebase Authentication
  • Test-driven development workflows
  • Cross-platform app testing
  • CI/CD pipelines requiring stable test runs

Considerations

  • Not for production use
  • Requires firebase_auth_mocks for full functionality
  • Mock behavior must be explicitly defined in tests
  • Limited to sign-in simulation, not full OAuth flow
  • Does not handle real Google account interactions

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Mocks for google_sign_in. Use this package with firebase_auth_mocks to write unit tests involving Firebase Authentication.

pub package unit-tests Buy Me A Coffee

Usage

A simple usage example:

import 'package:google_sign_in_mocks/google_sign_in_mocks.dart';
import 'package:test/test.dart';

void main() {
  late MockGoogleSignIn googleSignIn;
  setUp(() {
    googleSignIn = MockGoogleSignIn();
  });

  test('should return idToken when authenticating', () async {
    final signInAccount = await googleSignIn.signIn();
    final signInAuthentication = await signInAccount!.authentication;
    expect(signInAuthentication, isNotNull);
    expect(googleSignIn.currentUser, isNotNull);
    expect(signInAuthentication.idToken, isNotNull);
  });

  test('should return null when google login is cancelled by the user',
      () async {
    googleSignIn.setIsCancelled(true);
    final signInAccount = await googleSignIn.signIn();
    expect(signInAccount, isNull);
  });
  test('testing google login twice, once cancelled, once not cancelled at the same test.', () async {
   googleSignIn.setIsCancelled(true);
    final signInAccount = await googleSignIn.signIn();
    expect(signInAccount, isNull);
    googleSignIn.setIsCancelled(false);
    final signInAccountSecondAttempt = await googleSignIn.signIn();
    expect(signInAccountSecondAttempt, isNotNull);
  });
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

Categories

Dependencies

Dependency list 2 items

Source repository

Projects using this package

No data available yet.