无法使用浓缩咖啡来启动该应用程序



我已经编写了基本的Android仪器代码,以使用应用程序活动启动该应用程序。问题是,它启动了应用程序并立即关闭。

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仪器测试来运行此示例活动,并且无法启动该应用程序。

您的代码是绝对正确的,并且仅写了应用程序,但是,如果您想在启动后持有它,则必须在public void TestCompose(({}方法中添加一些代码行。您可以使用onview(withID(r.id.x((添加行;等,那么它不会突然关闭该应用程序。或者您也可以添加此行,thread.sleep(1000(;

最新更新