Android 浓缩咖啡活动测试规则赢得';t在第一次测试后重新启动活动
我无法进行浓缩咖啡测试。在我的第一个测试运行后,它将无法启动下一个意图并达到超时Android 浓缩咖啡活动测试规则赢得';t在第一次测试后重新启动活动,android,android-espresso,Android,Android Espresso,我无法进行浓缩咖啡测试。在我的第一个测试运行后,它将无法启动下一个意图并达到超时 java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=se.liu.ida.sambandssystem/.Authentication } within 45 seconds. Perhaps the main thread has not
java.lang.RuntimeException: Could not launch intent Intent {
act=android.intent.action.MAIN flg=0x10000000
cmp=se.liu.ida.sambandssystem/.Authentication } within 45 seconds.
Perhaps the main thread has not gone idle within a reasonable amount
of time? There could be an animation or something constantly
repainting the screen. Or the activity is doing network calls on
creation? See the threaddump logs. For your reference the last time
the event queue was idle before your activity launch request was
1492675509022 and now the last time the queue went idle was:
1492675551675. If these numbers are the same your activity might be
hogging the event queue...
我尝试过不同类型的测试规则,甚至是带有显式finishActivity()
和relaunchActivity()
方法的自定义测试规则,但都不起作用。应用程序正在进行网络调用,我在第一次测试后尝试断开它,但也没有成功。有人知道如何在每次启动后强制退出应用程序吗
下面是一些来自测试的示例代码:
@RunWith(AndroidJUnit4.class)
public class AuthenticationTest {
private String mNFC, mPassword;
private int nrOfruns;
private IdlingResource mIdlingResource;
private AuthenticationUtil util;
@Rule
public IntentsTestRule<Authentication> mActivityTestRule =
new IntentsTestRule<Authentication>(
Authentication.class,
false, //Inital touchmode
true //LaunchActivity
);
@Before
public void registerIdlingResource() {
mIdlingResource = mActivityTestRule.getActivity().getIdlingResource();
Espresso.registerIdlingResources(mIdlingResource);
}
@After
public void unregisterIdlingResource() throws Service.NotInitializedException {
if (mIdlingResource != null) {
Espresso.unregisterIdlingResources(mIdlingResource);
}
Log.d("TEST", "Unregistering Espresso Idling resource");
}
@Before
public void initValidLogin() throws InterruptedException, Service.NotInitializedException {
nrOfruns = 10;
validNFC = "11111111";
validPassword = "password";
util = new AuthenticationUtil(); //Espresso code for clicking login buttons like a user would
util.logOutIfLocked();
}
@Test
public void validAuthenticationTest() throws Exception {
Log.d("TEST", "Valid authentication test...");
util.authenticate(validNFC, validPassword);
//Log out after successful log in
onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer());
onView(withId(R.id.nav_view))
.perform(NavigationViewActions.navigateTo(R.id.nav_logout));
onView(withText("Log out")).perform(click());
Log.d("TEST", "Valid authentication test complete");
}
@Test
public void invalidLogInTest() throws InterruptedException {
Log.d("TEST","Invalid authentication test...");
HashMap<String, String> invalidLogins = createInvalidLogins(nrOfruns);
for (HashMap.Entry<String, String> invalidLogin : invalidLogins.entrySet()){
util.authenticate(invalidLogin.getKey(), invalidLogin.getValue());
}
}
@RunWith(AndroidJUnit4.class)
公共类身份验证测试{
专用字符串mNFC,mPassword;
私家车;
私有资源;
私有身份验证util util;
@统治
公共意图测试规则MacTivityStrule=
新的IntentsTestRule(
身份验证类,
false,//初始接触模式
true//启动活动
);
@以前
公共无效registerIdlingResource(){
mIdlingResource=mActivityTestRule.getActivity().getIdlingResource();
浓缩咖啡注册资源(mIdlingResource);
}
@之后
public void unregisterIdlingResource()引发Service.NotInitializedException{
if(mIdlingResource!=null){
浓缩咖啡。未注册的入口资源(mIdlingResource);
}
Log.d(“测试”,“注销浓缩咖啡闲置资源”);
}
@以前
public void initValidLogin()引发InterruptedException,Service.NotInitializedException{
nrOfruns=10;
validNFC=“11111111”;
validPassword=“密码”;
util=newauthenticationutil();//用于像用户一样单击登录按钮的浓缩咖啡代码
util.logOutIfLocked();
}
@试验
public void validAuthenticationTest()引发异常{
Log.d(“测试”,“有效身份验证测试…”);
util.authenticate(validNFC,validPassword);
//成功登录后注销
onView(带id(R.id.drawer_布局)).perform(actionOpenDrawer());
onView(带id(R.id.nav_视图))
.执行(NavigationViewActions.navigateTo(R.id.nav_注销));
onView(使用文本(“注销”))。执行(单击();
Log.d(“测试”,“有效身份验证测试完成”);
}
@试验
public void invalidLogInTest()引发InterruptedException{
Log.d(“测试”,“无效身份验证测试…”);
HashMap invalidLogins=createInvalidLogins(nrOfruns);
对于(HashMap.Entry invalidLogin:invalidLogins.entrySet()){
authenticate(invalidLogin.getKey(),invalidLogin.getValue());
}
}
如果单独启动,这些测试可以工作,但是我想测试是否可以放在同一个类中,但不同的方法中
编辑:问题是我们的应用程序创建了许多toast消息,这些消息排队,禁止下一次启动。删除所有toast后,测试按预期进行。我遇到了同样的问题,但没有toast。我不知道是什么阻止了这些意图。你能解决问题吗?事实上,我知道了我有同样的问题,但是没有祝酒。我不知道是什么阻碍了我的意图。你能解决这个问题吗?事实上我有这些错误