Android Studio imports existing unit tests "Unable to find hardware information"

So, I try our Android studio and test a project that worked in eclipse. I have everything that compiles and the application will run fine, but I can’t modify my unit tests and work. In the end, I compiled them by adding the application folder as a dependency, but I don’t think my launch configuration is correct, because whenever I run my tests, I get this error

Installing <packagename> DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/<packagename>" pkg: /data/local/tmp/<packagename> Success Running tests Test running started Test running failed: Unable to find instrumentation info for: ComponentInfo{<packagename>/android.test.InstrumentationTestRunner} Empty test suite. 

Edit: For all new members, the state of Android Studio has changed a lot since I originally posted this question, but many helpful people continued to post their specific solution for this error. I would advise sorting by active and checking the latest answers first.

+56
android android-studio junit
May 16 '13 at 15:24
source share
13 answers

If you have testInstrumentationRunner defined in your build.gradle , for example:

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

make sure that in the launch configuration window you use the same “Special Measuring Instrument” in your Android Studio / IntelliJ configuration for your test.

+58
Apr 23 '14 at 12:39 on
source share

In my case, the solution was:

  • Browse> Toolbar> Build Options
  • Select option * Debug
+18
Dec 17 '13 at 17:19
source share

Explanation and solution

This " Unable to find hardware " error appears if targetPackage declared in the test application manifest is different from the package declared in the test application manifest:

  • Checked application:

     <manifest package="com.example.appbeingtested" … > 
  • Testing:

     <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.appbeingtested" … /> 
+17
Jul 15 '13 at 11:39 on
source share

I solved this problem by changing

 android.test.InstrumentationTestRunner 

at

 com.android.test.runner.MultiDexTestRunner 

on the EditConfigurations tab → Specific Instrumentation Runner (optional).

It turns out because my application uses MultiDex, I need to also change the test runner to MultiDexTestRunner.

UPDATE:

As @dan's comment, InstrumentationTestRunner deprecated using AndroidJUnitRunner instead.

+16
May 16 '16 at 3:12
source share

In my case, the Run / Debug Configurations errors were incorrect.

One solution:

  • Go to "Run / Debug Configurations"

    Run → Change Configurations ...

  • Setting up an Android test for a test class

  • Select your Android test configuration on the left side or create a new one with a plus icon and name it, for example. ClassNameTest

  • Select the module containing your test class. In the simplest case, the test class is in your application module, so select the application.

  • Select the test configuration on the next line. I use:

    • Class: to run all tests of the same class.
  • Choosing a test class

  • Finally configure the target device and select ok.

+4
Mar 31 '15 at 16:14
source share

This only works in AndroidStudio version. 2.3

In my case, the wrong tool runner was selected.

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

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

+4
Apr 13 '16 at 11:50
source share

I have the same problem as @Iuliia Ashomok and tried everything online.

Still out of luck.

After a 2-day investigation, I found that the problem is being created by a mobile phone..V.

I originally used Xiaomi Mi4i as a test device (with root), and tests could not be run. Of course, I got the error below.

 Test running failed: Unable to find instrumentation info for: ComponentInfo{<packagename>/android.test.InstrumentationTestRunner} 

However, when I use the Sony Xperia Z3 (no root), everything works well.

+2
Mar 01 '16 at 10:17
source share

These are the seams; you do not have a good project structure.

  • Open AndroidManifest.xml and check if it has

     <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.YourClass" android:label="Tests for com.example.YourClass"/> 

If NO, do the following:

  • Reorganize the directory structure to the following: (this is a recommendation from an official source )
  MyProject/ AndroidManifest.xml res/ ... (resources for main application) src/ ... (source code for main application) ... tests/ AndroidManifest.xml res/ ... (resources for tests) src/ ... (source code for tests) 
  1. You see that you need an internal test module.
    To create it in the Idea IDE, run the following File → New Module → Test Module . After creating, you can see one new AndroidManifest.xml. And inside it there is documentation .
+1
Jun 22 '15 at 2:05
source share

I got this error. I am using sdk tools in CLI mode. And the error occurred when I ran the 'ant test' in a test project. Later I noticed that I didn’t even build and install a test project before! (with 'ant debug install') Therefore, you should try checking your current configuration to make sure that the test project received an efficient build before running the test. In another case, Android Studio uses Gradle. I don't know this well, but try checking out the Gradle settings for a project or Gradle settings file.

0
Jul 03 '13 at 16:42
source share

For me, the problem is related to this dependency:

 debugCompile 'com.android.support.test:rules:0.2' 

After I deleted it, my tests were found and run again.

Please note that I did not receive the message “Could not find hardware”, but the message “No tests found”.

0
Jul 23 '15 at 7:41
source share

It turned out to be a delay problem. It was automatically fixed after I had been waiting for a long time to read Internet solutions. I recompiled the code and it worked.

0
Dec 09 '15 at 19:18
source share

Since none of these answers helped me, I wanted to share my solution for those who are as desperate as I am. :)

Due to the testing libraries I used, I needed to enable multidex support by adding multiDexEnabled true to my Gradle construct. I'm not sure I had multidex support fully implemented (the correct way to do this has changed since I last implemented it), but in the end I did not need it, and removing this line from my assembly fixed the error. My team had several testing problems at work related to supporting multidex support ... in a typical Android style.

0
Apr 22 '16 at 0:34
source share

In my case, in the same classes, in some test cases, the correct test runner (android.support.test.runner.AndroidJUnitRunner) was selected, which was defined in build.gradle, and in some test cases, android.test.InstrumentationTestRunner was collected, which is not was defined, at least in Manifest or build.gradle or configuration editing. Ideally, this should have been resolved using the Sync project with the Gralde parameter, although this did not work.

Finally, I found the wrong test runner defined against the method in .idea/workspace.xml , I changed it manually, and the problem was resolved.

As a rule, we should not edit this generated Android Studio file, but for me it worked as the last option.

0
Sep 05 '17 at 9:35 on
source share



All Articles