2017-03-23 3 views
0

Ich versuche, Setup und Instrumental Unit Test für Activity mit FirebaseAuth. Wenn ich die Anwendung starte, funktioniert alles gut. Das Problem liegt in der Einrichtung von Instrumenten-Komponententests.Instrumental Unit Tests der Aktivität mit FirebaseAuth

Aktivität:

public final class GoogleSignInActivity extends AppCompatActivity{ 
    @Override 
    protected void onCreate(final Bundle savedInstanceState) { 
     ... 
     if (FirebaseApp.getApps(this).isEmpty()) { 
     FirebaseApp.initializeApp(this); 
     } 

     mFirebaseAuth = FirebaseAuth.getInstance(); 
    } 
} 

Test:

@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()); 
} 

}

Exception (nur wenn Test ausgeführt wird, nicht app):

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

Überprüfen Sie, ob Sie FirebaseApp.initializeApp (InstrumentationRegistry.getContext()) wirklich aufrufen; im Setup. Ich denke, du wurdest nie wegen dieser Bedingung gerufen. –

+0

@MaherAbuthraa Ich habe es bereits vorher überprüft. Sogar versucht, es ohne Bedingung hinzuzufügen .... es wird aufgerufen. –

+0

Haben Sie eine Lösung gefunden? Ich stehe vor demselben Problem – Bedant

Antwort

1

Ich denke, Ihr Problem mit ApplicationID (a.k.a Paketname). Sie sollten auch Ihre Anwendungs-ID zum Testen zum Firebase-Projektkonto hinzufügen.

hat Suffix: Test

Im Allgemeinen sieht es so aus:

[ApplicationID] .test

dh

com.apipas.android .hello.test

Release applicationId ist

com.apipas.android.hello

Ich hoffe, dass Sie helfen können, ".