2017-03-23 62 views
0

我正在嘗試使用FirebaseAuthActivity進行設置和儀器單元測試。當我運行應用程序時,一切正常。問題出現在儀器單元測試的設置中。使用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. 
+0

檢查是否確實調用了FirebaseApp.initializeApp(InstrumentationRegistry.getContext());在設置。我想你從來沒有因爲這種情況而被叫過 –

+0

@MaherAbuthraa我已經檢查過它。即使試圖無條件添加它....它被調用。 –

+0

您是否找到任何解決方案?我面臨同樣的問題 – Bedant

回答

1

我認爲你的applicationID(a.k.a包名)的問題。您應該將您的應用程序ID添加到Firebase項目帳戶以進行測試。

它具有後綴:測試

一般來說它看起來像:

[的applicationID]。測試

com.apipas.android .hello.test

發佈的applicationID是

com.apipas.android.hello

我希望可以幫助你「。