Test running failed: Unable to find instrumentation info for: ComponentInfo{} — error trying to test in IntelliJ with Gradle

后端 未结 10 1879
野的像风
野的像风 2021-02-01 01:14

Everytime I try to run my tests the console says this:

Running tests
Test running startedTest running failed: Unable to find instrumentation info for:
ComponentI         


        
10条回答
  •  庸人自扰
    2021-02-01 01:35

    I had to do a combination of VikingGlen's answer, Liuting's answer, and this answer. This answer works for Android Studio version 2.1.

    1. Run -> Edit Configurations... -> General -> Specific instrumentation runner (optional): "android.support.test.runner.AndroidJUnitRunner"

    2. In build.gradle (the one with all your dependencies), put this:

    defaultConfig {
       testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    } 
    

    Then it could run tests of this type:

    @RunWith(AndroidJUnit4.class)
    @LargeTest
    public class ApplicationTest {
    
        @Rule
        public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
    
        @Test
        public void login() {
            //Open Drawer to click on navigation.
            onView(withId(R.id.drawer_layout))
                    .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed.
                    .perform(open()); // Open Drawer
        }
    }
    

提交回复
热议问题