【问题标题】:How to debug instrumentation tests in Android Studio?如何在 Android Studio 中调试仪器测试?
【发布时间】:2016-04-28 15:40:26
【问题描述】:

在 Android Studio 中,当我调试仪器测试时,测试不会在任何断点处停止。调试单元测试有效。我有一个简单的仪器测试,只检查用户名edittext是否显示:

@RunWith(AndroidJUnit4.class)
public class LogonActivityTest {

    @Rule
    public ActivityTestRule<LogOnActivity> mActivityRule = new ActivityTestRule<>(LogOnActivity.class, true, false);

    @Before
    public void setUp() throws Exception {
        mActivityRule.launchActivity(new Intent()); // breakpoint here
    }

    @Test
    public void testSimple() throws Exception {
        onView(withId(R.id.act_logon_et_username)).check(matches(isDisplayed())); // breakpoint here
    }
}

build.gradle我已经正确设置了

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

如何调试插桩测试?我正在使用 Espresso、Mockito 和 Dagger 2。

【问题讨论】:

    标签: android android-studio mockito android-testing android-espresso


    【解决方案1】:

    您可以通过以下几种方式解决此问题 Tomask。

    如果您从命令行调用测试,您可以在配置中为您的测试传递选项 -e debug true。

    否则,更简单地说,从 android studio 开始测试时,您应该选择 Debug 而不是 Run。如果您从 android studio 为您的测试单击 Run,选项 -e debug false 会被设置,并且测试不会在断点处停止执行。

    希望这会有所帮助!

    【讨论】:

    • 问题是虽然我的测试在断点处停止了执行,但它只停止了几秒钟,我无法检查我想要的。
    猜你喜欢
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-22
    相关资源
    最近更新 更多