【问题标题】:Testing: Stubbing reauthenticateWithCredential Difficulty with Mocks测试:使用 Mocks 对 reauthenticateWithCredential 难度进行存根
【发布时间】:2021-09-07 01:29:13
【问题描述】:

我很难让这个存根工作。我希望工作的解决方案是

when(user.reauthenticateWithCredential(MockAuthCredential())).thenAnswer((_) async => MockUserCredential());

但我不断收到错误

在运行测试时引发了以下 MissingStubError: 'reauthenticateWithCredential' 未找到与此方法调用的参数匹配的存根: reauthenticateWithCredential(AuthCredential(providerId:密码,signInMethod:密码,令牌: 无效的)) 使用 Mockito 的 'when' API 为这个方法添加一个存根,或者为 MockUser 生成模拟 'returnNullOnMissingStub: true'。

reauthenticateWithCredential 的实现如果需要参考

  Future<UserCredential> reauthenticateWithCredential(
    AuthCredential credential,
  ) async {
    return UserCredential._(
      _auth,
      await _delegate.reauthenticateWithCredential(credential),
    );
  }

还有我的定位器是如何设置的

late User user;
user = MockUser();
locator.registerSingleton<User>(user);

我做错了什么?谢谢。

【问题讨论】:

    标签: dart firebase-authentication mocking mockito stub


    【解决方案1】:

    答案是改变

    late User 用户转换为 Late MockUser 用户,然后使用 any 代替 MockAuthCredential()。

    【讨论】:

    • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
    猜你喜欢
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多