0
我正在嘗試使用FirebaseAuth
對Activity
進行設置和儀器單元測試。當我運行應用程序時,一切正常。問題出現在儀器單元測試的設置中。使用FirebaseAuth進行的活動的儀器單元測試
活動:
public final class GoogleSignInActivity extends AppCompatActivity{
@Override
protected void onCreate(final Bundle savedInstanceState) {
...
if (FirebaseApp.getApps(this).isEmpty()) {
FirebaseApp.initializeApp(this);
}
mFirebaseAuth = FirebaseAuth.getInstance();
}
}
測試:
@RunWith(AndroidJUnit4.class)
public class GoogleSignInActivityIntegrationTest extends UiTestPrerequesites {
@Rule
public final ActivityTestRule<GoogleSignInActivity> mActivityRule = new ActivityTestRule<>(
GoogleSignInActivity.class, false, true);
@Before
public void setup(){
if (FirebaseApp.getApps(InstrumentationRegistry.getContext()).isEmpty()) {
FirebaseApp.initializeApp(InstrumentationRegistry.getContext());
}
}
@Test
@SmallTest
public void implements_GoogleSignInWorkerFragment_GoogleSignInUiChangesListener() {
//FirebaseApp.initializeApp(InstrumentationRegistry.getContext()); (this doesn't help)
assertThat(mActivityRule .getActivity(),
notNullValue());
}
}
的異常(只運行試驗時,不應用):
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.twofortyfouram.ui.test. Make sure to call FirebaseApp.initializeApp(Context) first.
檢查是否確實調用了FirebaseApp.initializeApp(InstrumentationRegistry.getContext());在設置。我想你從來沒有因爲這種情況而被叫過 –
@MaherAbuthraa我已經檢查過它。即使試圖無條件添加它....它被調用。 –
您是否找到任何解決方案?我面臨同樣的問題 – Bedant