简体   繁体   English

Android 测试给出了一个 IllegalStateException:没有注册检测

[英]Android testing give a IllegalStateException: No instrumentation registered

I writing my first android test following by google tutorial and ofcourse I got error:我按照谷歌教程编写了我的第一个 android 测试,当然我遇到了错误:

java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.

my code:我的代码:

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 ?如何解决?

If you use robolectric 4.0+, you need to use androidx dependencies, eg如果您使用 robolectric 4.0+,则需要使用androidx依赖项,例如

dependencies {
    testImplementation "androidx.test.ext:junit:1.0.0"
    testImplementation "androidx.test:rules:1.1.0"
}

instread of android support ones.安装 android 支持的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 仪器测试:没有仪器注册错误 - Android Instrumentation Testing: No instrumentation registered Error java.lang.IllegalStateException:未注册检测! 必须在注册仪器下运行 - java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation Android Instrumentation 测试 - UI 线程问题 - Android Instrumentation Testing - UI Thread Issues 没有仪器注册! 必须在注册仪器下运行 - No instrumentation registered! Must run under a registering instrumentation 无法解决以下活动:仪器测试 android 活动时的意图 - Unable to resolve activity for: Intent when instrumentation-testing android activities Android中的检测 - Instrumentation in Android 错误 - 没有注册仪器!必须在注册仪器下运行 - Error - No instrumentation registered! Must run under a registering instrumentation 没有注册的仪器,运行单元测试时出错 - No registered instrumentation, errors when running unit tests IllegalStateException:没有在单元测试中为范围'session'注册的Scope - IllegalStateException: No Scope registered for scope 'session' on unit test SOAPUI Java非法状态异常方案“ https”未注册 - SOAPUI java illegalstateexception scheme 'https' not registered
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM