Android Studio import existing unit tests “Unable to find instrumentation info”

前端 未结 15 1823
故里飘歌
故里飘歌 2021-02-01 12:17

So I\'m trying our Android Studio and testing a project that worked in eclipse. I got everything compiling and the application will launch just fine, but I can\'t get my unit te

相关标签:
15条回答
  • 2021-02-01 12:46

    Since none of these answers helped me, I wanted to share my solution for anyone who is as desperate as I was. :)

    Because of the testing libraries that I was using, I needed to enable multidex support by adding multiDexEnabled true to my Gradle build. I'm not sure I had multidex support fully implemented to begin with (the proper way of doing it has changed since I last implemented it) but ultimately, I didn't end up needing it and removing that line from my build fixed the error. My team at work has had a few testing issues related to enabling multidex support… in typical Android style.

    0 讨论(0)
  • 2021-02-01 12:47

    I solved this problem by changing

    android.test.InstrumentationTestRunner 
    

    into

    com.android.test.runner.MultiDexTestRunner
    

    in EditConfigurations -> Specific Instrumentation Runner (optional) tab.

    Turns out, because my app is using MultiDex, I need to change test runner to MultiDexTestRunner as well.

    UPDATE:

    As @dan comment, InstrumentationTestRunner is deprecated use AndroidJUnitRunner instead.

    0 讨论(0)
  • 2021-02-01 12:49

    In my case the Run/Debug Configurations were wrong.

    One Solution:

    1. Go to Run/Debug Configurations

      Run -> Edit Configurations...

    2. Setup a Android-Test for your test class

    3. Select your Android test configuration on the left side
      or create a new one with the plus icon and name it e.g. ClassNameTest

    4. Select the module containing your test class. In the simplest case the test class is in your app module so select app.

    5. Select on the next row your test configuration. I use:

      • Class: to run all tests of one class.
    6. Choice your test class

    7. Finally configure your target device and select ok.

    0 讨论(0)
  • 2021-02-01 12:50

    This answer is going to explain the history issues and summarise all related settings.

    Basically there are 3 possible places for instrumentation test runner configurations.

    1. In EditConfigurations -> General tab -> Specific Instrumentation Runner (optional)
      This is existing in Android Studio 2.2 and version before only, in latest version, it is removed already.

    2. In manifest file, the test runner is configured as below.

        < instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
               android:targetPackage="com.mytestapp.test"/>
    

    Since "android.test.InstrumentationTestRunner" is deprecated in API level 24, this setting is also not necessary already, as long as you configure the runner in gradle file.
    If you want to keep this setting, please make sure the runner name should match to the one you set in the gradle file, otherwise you will got this error also.

    1. In gradle file.
      This is the only recommended way if you use Android Studio v2.3 above.
        android {
        .......
            defaultConfig {  
                .......  
                testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"  
            }   
        }
    
    0 讨论(0)
  • 2021-02-01 12:55

    This only works in AndroidStudio Version < 2.3

    In my case the wrong instrumentation runner was selected.

    I fixed this by specifying the instrumentation runner in the Run/Debug Configuration of the test (see below). There you can select a runner from the list. 1]

    You find the Run/Debug Configurations: Run -> Edit Configurations ...

    0 讨论(0)
  • 2021-02-01 12:56

    If you have a testInstrumentationRunner defined in your build.gradle such as this:

    android {
        defaultConfig {
            testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    

    make sure that in the run configuration window you use the exact same "Specific instrumentation runner" in your Android Studio / IntelliJ run configuration for your test.

    0 讨论(0)
提交回复
热议问题