FirebaseデータベースとFirebase Authを使用するプレゼンター向けの簡単なRobolectricテストを作成しようとしています。しかし、テストを開始しようとするたびに、IllegalStateExceptionがスローされます。FirebaseでのRobolectricアプリケーションテスト
java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
私のテスト私のプレゼンターのコンストラクタで、私はちょうどFirebaseインスタンスを取得しながら
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class LoginPresenterTest {
private LoginPresenter presenter;
private LoginMvpView view;
@Before
public void beforeEachTest() {
presenter = new LoginPresenter();
view = new LoginFragment();
}
@Test
public void attachView_shouldAttachViewToThePresenter() {
presenter.attachView(view);
assertSame(presenter.getMvpView(), view);
}
}
非常に簡単です。
public LoginPresenter() {
this.firebaseAuth = FirebaseAuth.getInstance();
this.database = FirebaseDatabase.getInstance().getReference();
}
Robolectric with Firebaseを使用する方法はありますか?
?あなたのテストでそれらをしたいですか? –
いいえ、私はまだそれらを必要としません。あなたはそれらを模擬する方法の詳細を教えてください。私はテストするのが初めてです。 – Prokky