gpt4 book ai didi

android - 无法使用 Espresso 启动应用程序

转载 作者:行者123 更新时间:2023-12-05 00:05:55 27 4
gpt4 key购买 nike

我已经编写了一个基本的 android 检测代码来使用应用程序 Activity 启动应用程序。问题是,它会启动应用程序并立即将其关闭。

package com.esse.mail;

import android.content.Intent;
import android.support.test.espresso.ViewAssertion;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

@RunWith(AndroidJUnit4.class)
public class HomeScreenTest
{
@Rule
public ActivityTestRule<HomeScreenActivity> mActivityRule = new
ActivityTestRule<>(HomeScreenActivity.class);

@Before
public void setUp()
{
mActivityRule.launchActivity(new Intent());
}

@Test
public void testCompose()
{

}

@After
public void tearDown()
{

}
}

07/03 13:17:28: Launching HomeScreenTest
No apk changes detected since last installation, skipping installation of /Users/webyog/gem-test/falcon/mail/app/build/outputs/apk/debug/app-debug.apk
$ adb push /Users/webyog/gem-test/falcon/mail/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk /data/local/tmp/com.esse.mail.test
$ adb shell pm install --full -t -r "/data/local/tmp/com.esse.mail.test"
Success
APK installed in 385 ms
Running tests

$ adb shell am instrument -w -r -e debug false -e class 'com.esse.mail.HomeScreenTest' com.esse.mail.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests

我正在尝试使用 android 插桩测试运行此示例 Activity ,但无法启动该应用。

最佳答案

你的代码是绝对正确的,它只是为了启动应用程序而编写的,但是如果你想在启动后保持它,那么你将不得不在 public void testCompose(){} 方法中添加一些代码行。您可以使用 onView(withId(R.id.X)); 添加行等等,那么它就不会突然关闭应用程序。或者你也可以添加这一行,线程. sleep (1000);

关于android - 无法使用 Espresso 启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56865446/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com