我按照谷歌教程编写了我的第一个 Android 测试,当然我得到了错误:
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)));
}
}
我还没有在堆栈中找到解决方案。
如何修复它?
如果您使用robolectric 4.0+,则需要使用androidx
依赖关系,例如
dependencies {
testImplementation "androidx.test.ext:junit:1.0.0"
testImplementation "androidx.test:rules:1.1.0"
}
而不是 Android 支持的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)