Search code examples
androidandroid-espressoandroid-multidex

Test running failed: Unable to find instrumentation info for: ComponentInfo{com.view.asim.mixuntong.test/android.test.InstrumentationTestRunner}


I use Android studio verison 2.3.1,and I want to use espresso for testing,but encountered a problem as follow image Test running failed

my test java file

package com.view.asim;

import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.view.asim.activity.MainActivity;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
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;

/**
 * Created by OF on 2017/4/28.
 */

@RunWith(AndroidJUnit4.class)
@LargeTest
public class MakeSureLogin {
    private String mStringToBetyped;
    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
            MainActivity.class);

    @Before
    public void initValidString() {
        // Specify a valid string.
    }

    @Test
    public void changeText_sameActivity() {

        // Check that the text was changed.
        onView(withId(R.id.account_txt)).perform().check(matches(withText(mStringToBetyped)));

    }
}

I knew there are similar questions in stackoverflow had been asked and some guys anwsered too,but those solutions(like this) can't resolve my problem. Somebody said that can specific instrumentation runner ,but there is not the action in Android studio version 2.3.I think it may be relevant of multildex ,really hope some guys can help me,any suggestion will very appreciated.Here my build.gralde file

    defaultConfig {
       //...
       multiDexEnabled true
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
       //...
    }
    productFlavors {
           zixuntong{
                applicationIdSuffix ".mixuntong"
                manifestPlaceholders = otherHolderMap
                manifestPlaceholders.put("PACKAGE_NAME",ASIM_PKG_NAME+applicationIdSuffix)
                buildConfigField "boolean", "isAddShare", "false"
                buildConfigField "boolean", "isZXT", "true"
            }
    }
        //.....
        androidTestZixuntongCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
                exclude group: 'com.android.support', module: 'support-annotations'
            })




   //    compile 'com.android.support:support-annotations:22.2.0'
        androidTestZixuntongCompile 'com.android.support.test:runner:0.5'
        testCompile 'junit:junit:4.12'
        androidTestZixuntongCompile('com.android.support:multidex-instrumentation:1.0.1') {
            exclude group: 'com.android.support', module: 'multidex'
        }
        configurations.all {
            resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
        }
    //...
//had trying follow script,but still doesn't work
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',

{ exclude group: 'com.android.support', module: 'support-annotations' })


Solution

  • I found that I had fixed this issue after upgrading Android Studio from 2.3.1 to 2.3.2.