2017-03-23 11 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プロジェクトアカウントに追加する必要があります。

それは接尾辞を持っています

com.apipas.androidすなわち

[APPLICATIONID] .TEST

テスト

は、一般的には次のようになります.hello.test

リリースAPPLICATIONIDは、「私は、あなたを助けることを願っていcom.apipas.android.hello

です。

関連する問題