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
In my case in same classes some test cases were picking correct test runner ( android.support.test.runner.AndroidJUnitRunner ) which was defined in build.gradle, and some test cases were picking up android.test.InstrumentationTestRunner, which was not defined at least in Manifest or build.gradle or edit configuration. Ideally it should have been resolved by Sync Project with Gralde option, though it didn't work.
At last I found wrong test runner defined against a method in .idea/workspace.xml
, I changed it manually, and issue got resolved.
Generally we are not supposed to edit this Android Studio generated file, but for me it did worked as last option.
It seams you have not good project structure.
Open AndroidManifest.xml and check does it have
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.YourClass"
android:label="Tests for com.example.YourClass"/>
If NO do next:
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)
In my case, the issue was in device too. Other devices were working fine. Simple uninstall and reinstall fixed it.
In my case, the solution was:
Explanation and solution
This error "Unable to find instrumentation" appears if targetPackage declared in the manifest of the test application is different from the package declared in the manifest of the application being tested:
Application being tested:
<manifest package="com.example.appbeingtested" … >
Test application :
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.appbeingtested" … />
It turned out to be a delay problem. It fixed automatically after I waited a while reading the Internet solutions. I recompiled the code, and it worked.