Android 测试给出了一个 IllegalStateException:没有注册检测 [英] Android testing give a IllegalStateException: No instrumentation registered
本文介绍了Android 测试给出了一个 IllegalStateException:没有注册检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我按照谷歌教程编写了我的第一个 android 测试,当然我遇到了错误:
I writing my first android test following by google tutorial and ofcourse I got error:
java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.
我的代码:
package com.mikk.expressotest;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.core.app.ActivityScenario;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityTest {
@Before
public void setUp() {
ActivityScenario.launch(MainActivity.class);
}
@Test
public void changeText_showHi() {
onView(withId(R.id.btnOne)).perform(click());
onView(withId(R.id.tvOne)).check(matches(withText(R.string.hi)));
}
}
我还没有在堆栈中找到解决方案.
如何解决?
I have not found solution in stack.
How to fix it ?
推荐答案
如果你使用robolectric 4.0+,你需要使用androidx
依赖,例如
If you use robolectric 4.0+, you need to use androidx
dependencies, e.g.
dependencies {
testImplementation "androidx.test.ext:junit:1.0.0"
testImplementation "androidx.test:rules:1.1.0"
}
替代安卓支持的.
这篇关于Android 测试给出了一个 IllegalStateException:没有注册检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文