【问题标题】:How do you write integration tests for Firestore on Unity?您如何在 Unity 上为 Firestore 编写集成测试?
【发布时间】:2021-09-10 03:10:27
【问题描述】:

我有一个由 Firebase/Firestore 数据库支持的 Unity3D 应用。

Firebase 提供了一个Local Emulator Suite 用于测试,但it is not supported on Unity

似乎测试使用 Firestore 的逻辑的唯一方法是:

  1. 使用真实的仅用于测试的数据库并在每次设置时清除它
  2. 模拟 Firestore 的所有用法

(2) 似乎很容易出错,就像我在重新发明轮子一样。 (1) 看起来既危险又缓慢。我还缺少另一个广泛支持的选项吗?

【问题讨论】:

标签: firebase unit-testing unity3d google-cloud-firestore mocking


【解决方案1】:

现在支持模拟器套件。见https://github.com/firebase/quickstart-unity/issues/719#issuecomment-938759588

要使用模拟器,请运行

FirebaseFirestore firestore = FirebaseFirestore.DefaultInstance;
firestore.Settings.Host = "localhost:8080";
firestore.Settings.SslEnabled = false;

确保在使用的每个程序集中都使用此代码。许多教程都将测试作为其余代码在单独的程序集中运行。如果您的架构相似,则每个程序集中都需要上述代码。具体来说,请务必在访问 FirebaseFirestore.DefaultInstance 时在测试程序集中和游戏代码中调用此代码,因为 FirebaseFirestore.DefaultInstance 每个进程存在一次(即每个程序集一次)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 2014-04-13
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多