我需要有关travis CI的帮助!将不胜感激。所以我正在使用android 2.3.3和firebase作为我的后端。我正在运行用espresso编写的单元测试,以便在用户输入电子邮件和密码时登录。我也在使用travis ci和工作服。该测试通过了我的机器和travis ci,但在travis上检查工作服时,并非所有代码都运行。
这里是登录代码。
public void loginAccount(String email, String password){ //runs
mAuth.signInWithEmailAndPassword(email, password) //runs
.addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() { //runs
@Override
public void onComplete(@NonNull Task<AuthResult> task) { //does not run!!!!!!!!!!!!!!!!!!!
Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithEmail:failed", task.getException());
Toast.makeText(MainActivity.this, R.string.auth_failed,
Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this, "success",
Toast.LENGTH_SHORT).show();
Intent home = new Intent(MainActivity.this, HomeActivity.class);
startActivity(home);
}
// ...
}
});
}
前三行运行,但其余行不运行。
这里是测试文件。电子邮件和密码已经在数据库中,应该允许模拟器登录到应用程序。
private String mStringToBetyped;
private String mNumberToBetyped;
@Rule
public ActivityTestRule<MainActivity> mMainActivity = new ActivityTestRule<>(
MainActivity.class);
@Rule
public IntentsTestRule<HomeActivity> intentsTestRule =
new IntentsTestRule<>(HomeActivity.class,
true, // initialTouchMode
false); // launchActivity. False to set intent.
@Before
public void initValidString() {
// Specify a valid string.
mStringToBetyped = "[email protected]";
mNumberToBetyped = "12345678";
}
@Before
public void grantPermission() {
getInstrumentation().getUiAutomation().executeShellCommand(
"pm grant " + getTargetContext().getPackageName()
+ " android.permission.ACCESS_FINE_LOCATION");
getInstrumentation().getUiAutomation().executeShellCommand(
"pm grant " + getTargetContext().getPackageName()
+ " android.permission.INTERNET");
}
@Test
public void inputText_sameActivity() {
// Type text.
onView(withId(R.id.txt_email))
.perform(typeText(mStringToBetyped), closeSoftKeyboard());
onView(withId(R.id.txt_pass))
.perform(typeText(mNumberToBetyped), closeSoftKeyboard());
onView(withId(R.id.txt_email)).check(matches(withText(mStringToBetyped)));
onView(withId(R.id.txt_pass)).check(matches(withText(mNumberToBetyped)));
onView(withId(R.id.butn_login)).perform(click())
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
我需要运行的意图,以便可以在travis模拟器上继续所有测试。我读过不测试网络请求,但我不介意等待尽可能长的时间。我也读过用本地存储换出Firebase,但我不知道该怎么做。我需要travis来运行firebase代码并登录到模拟器上的应用程序。我知道我可以手动启动意图,但是接下来要测试loginAccount()了。帮助将不胜感激。
如果找到它,请共享解决方案,遇到同样的问题。