Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用FirebaseAuth对活动进行仪器单元测试_Android_Unit Testing_Firebase_Firebase Authentication - Fatal编程技术网

Android 使用FirebaseAuth对活动进行仪器单元测试

Android 使用FirebaseAuth对活动进行仪器单元测试,android,unit-testing,firebase,firebase-authentication,Android,Unit Testing,Firebase,Firebase Authentication,我正在尝试使用FirebaseAuth为活动设置和工具性单元测试。当我运行应用程序时,一切正常。问题在于仪器单元测试的设置 活动: 测试: 我认为你对applicationID的问题就是包名。您还应该将用于测试的应用程序Id添加到Firebase项目帐户 它有后缀:test 一般来说,它看起来像: [ApplicationID]。测试 i、 e com.apipas.android.hello.test 发布应用程序ID为 com.apipas.android.hello 我希望这会对您有所帮助

我正在尝试使用FirebaseAuth为活动设置和工具性单元测试。当我运行应用程序时,一切正常。问题在于仪器单元测试的设置

活动:

测试:


我认为你对applicationID的问题就是包名。您还应该将用于测试的应用程序Id添加到Firebase项目帐户

它有后缀:test

一般来说,它看起来像:

[ApplicationID]。测试

i、 e

com.apipas.android.hello.test

发布应用程序ID为

com.apipas.android.hello


我希望这会对您有所帮助。

检查您是否真的调用FirebaseApp.initializeAppInstrumentationRegistry.getContext;在设置中。我想你从来没有因为那件事被打过电话condition@MaherAbuthraa我以前已经检查过了。甚至试图无条件地添加它。。。。有人打电话给你,你找到解决办法了吗?我也面临同样的问题
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.