패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.16.0

firebase_auth_mocks

Firebase Auth용 가짜입니다. Firebase 인증을 포함한 단위 테스트를 작성하려면 `google_sign_in_mocks`와 함께 사용하세요.

AndroidiOSWebmacOSWindows
30일 다운로드
14.6만
좋아요
105
Pub 점수
140

패키지 설치

flutter pub add firebase_auth_mocks

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

실제 Firebase 백엔드에 연결하지 않고 인증 흐름을 시뮬레이션할 수 있도록 Firebase 인증을 위한 모의 구현을 제공하는 테스트 패키지입니다. `google_sign_in_mocks`와 함께 사용하여 Flutter 앱에서 인증 관련 로직의 단위 테스트를 용이하게 합니다. 제어된 환경에서 로그인, 로그아웃 및 사용자 상태 변경을 테스트하는 데 이상적입니다. Android, iOS, Web, macOS, Windows 등 모든 주요 플랫폼을 지원하여 환경 간 일관된 테스트 동작을 보장합니다.

사용 사례

  • 단위 테스트 인증 흐름
  • 사용자 로그인 및 로그아웃 시뮬레이션
  • 다른 인증 상태에서 앱 동작 테스트
  • 사용자 인증을 기반으로 한 UI 업데이트 검증
  • 오프라인 테스트 시나리오 개발

주요 기능

  • 모의 FirebaseAuth 인스턴스
  • google_sign_in_mocks와의 통합
  • 플랫폼에 관계없는 테스트
  • 모든 플러터 플랫폼을 지원합니다
  • 테스트 환경을 위한 간편한 설정

적합한 대상

  • Flutter 개발자가 테스트를 작성합니다
  • TDD 또는 BDD를 실천하는 팀
  • Firebase Auth에 크게 의존하는 앱
  • 테스트 주도 개발 워크플로
  • 신뢰할 수 있는 테스트가 필요한 CI/CD 파이프라인

고려 사항

  • 생산 환경 사용을 위한 것이 아님
  • 보조 google_sign_in_mocks가 필요합니다
  • 모크 동작은 실제 세계의 극단적인 케이스를 반영하지 않을 수 있습니다
  • 기본 인증 상태 시뮬레이션에 제한됨
  • 실시간 인증 리스너를 지원하지 않습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Firebase Auth Mocks

pub package Unit Tests Buy Me A Coffee

Mocks for Firebase Auth. Use this package with google_sign_in_mocks to write unit tests involving Firebase Authentication.

Usage

A simple usage example. Add firebase_auth_mocks and google_sign_in_mocks to dev dependencies.

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

main() {
    // Mock sign in with Google.
    final googleSignIn = MockGoogleSignIn();
    final signinAccount = await googleSignIn.signIn();
    final googleAuth = await signinAccount.authentication;
    final AuthCredential credential = GoogleAuthProvider.getCredential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );
    // Sign in.
    final user = MockUser(
      isAnonymous: false,
      uid: 'someuid',
      email: 'bob@somedomain.com',
      displayName: 'Bob',
    );
    final auth = MockFirebaseAuth(mockUser: user);
    final result = await auth.signInWithCredential(credential);
    final user = await result.user;
    print(user.displayName);
}

Features

  • MockFirebaseAuth supports:
    • instantiating in a signed-in state or not: MockFirebaseAuth(signedIn: true/false).
    • firing events on sign-in to authStateChanges and userChanges.
    • signInWithCredential, signInWithEmailAndPassword, signInWithCustomToken, signInAnonymously, createUserWithEmailAndPassword, signInWithPopup and signInWithProvider signs in.
    • sendSignInLinkToEmail, confirmPasswordReset and verifyPasswordResetCode.
    • verifyPhoneNumber resolves codeSent.
    • signOut
    • sendPasswordResetEmail
    • currentUser
    • the ability to throw exceptions using whenCalling(...).on(...).thenThrow(...). See usage details below. Currently these methods are supported: signInWithCredential, signInWithPopup, signInWithProvider, signInWithEmailAndPassword, createUserWithEmailAndPassword, signInWithCustomToken, signInAnonymously, signOut, sendPasswordResetEmail, sendSignInLinkToEmail, confirmPasswordReset, verifyPasswordResetCode. If you need another method supported, feel free to file a ticket, or better propose a PR.
    • pass auth information (uid, custom claims...) to Fake Cloud Firestore for security rules via authForFakeFirestore. See the docs at fake_cloud_firestore for usage.
    • authStateChanges, userChanges, idTokenChanges stream listeners
  • UserCredential contains the provided User with the information of your choice.
  • User supports:
    • updateDisplayName
    • reauthenticateWithCredential
    • updatePassword
    • delete
    • sendEmailVerification
    • getIdToken and getIdTokenResult
    • the ability to throw exceptions on reauthenticateWithCredential, updatePassword, delete, sendEmailVerification, verifyPhoneNumber, linkWithCredential, linkWithProvider, unlink, User.reload, User.verifyBeforeUpdateEmail.

Throwing exceptions

Regardless of the parameters
whenCalling(Invocation.method(#signInWithCredential, null))
  .on(auth)
  .thenThrow(FirebaseAuthException(code: 'bla'));
expect(
  () => auth.signInWithCredential(FakeAuthCredential()),
  throwsA(isA<FirebaseAuthException>()),
);
Depending on positional parameters
Equality
final auth = MockFirebaseAuth();
whenCalling(Invocation.method(#verifyPhoneNumber, '12-345-6789'))
    .on(auth)
    .thenThrow(FirebaseAuthException(code: 'invalid-action-code'));
expect(() => auth.verifyPhoneNumber('12-345-6789'),
    throwsA(isA<FirebaseAuthException>()));
expect(() => auth.verifyPhoneNumber('00-222-4444'),
    returnsNormally);
Using any other matcher

Supports all of the matchers from the Dart matchers library.

final auth = MockFirebaseAuth();
whenCalling(Invocation.method(
        #confirmPasswordReset, null, {#code: contains('code')}))
    .on(auth)
    .thenThrow(FirebaseAuthException(code: 'invalid-action-code'));
expect(
  () => auth.confirmPasswordReset(
    code: 'code',
    newPassword: 'password',
  ),
  throwsA(isA<FirebaseAuthException>()),
);
expect(
  () => auth.confirmPasswordReset(
    code: '1234',
    newPassword: 'password',
  ),
  returnsNormally,
);
Depending on named parameters

You can match some or all named parameters. If you omit a named parameter, the library matches it against anything.

In this example, it will throw an exception if the code contains the String 'code', no matter the value of newPassword.

whenCalling(Invocation.method(
          #confirmPasswordReset, null, {#code: contains('code')}))
      .on(auth)
      .thenThrow(FirebaseAuthException(code: 'invalid-action-code'));
  expect(
    () async => await auth.confirmPasswordReset(
      code: 'code',
      newPassword: 'password',
    ),
    throwsA(isA<FirebaseAuthException>()),
  );
  expect(
      () => auth.confirmPasswordReset(
            code: '10293',
            newPassword: 'password',
          ),
      returnsNormally);

Compatibility table

firebase_auth firebase_auth_mocks
6.0.0 0.15.0
5.0.0 0.14.0
4.0.0 0.9.0
3.5.0 0.8.7

Features and bugs

Please file feature requests and bugs at the issue tracker.

카테고리

의존성

의존성 목록 8 개

소스 저장소

이 패키지를 사용하는 프로젝트