2
votes

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.

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 ?

1

1 Answers

1
votes

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"
}

instread of android support ones.