我需要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);
}
// ...
}
});
}
前3行,但其余不行。
这是测试文件。电子邮件和密码已经在数据库中,应该允许模拟器登录到应用程序。
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 = "some_email@gmail.com";
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()的重点。将不胜感激。