Error in Android --Unable to find instrumentation info for: ComponentInfo

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

For Example I had an application that will invoke contacts and has to select one of the contact. But its not doing exactly what I want. It is showing me error Unable to find instrumentation info for: ComponentInfo{com.sample/com.sample.ContactsSelectInstrumentation}

Following is my Code.. This is my Activity class

 @Override   protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.go); button.setOnClickListener(mGoListener); } private OnClickListener mGoListener = new OnClickListener() { public void onClick(View v) {   startInstrumentation(new ComponentName(Test.this,       ContactsFilterInstrumentation.class), null, null); } }; 

And this is my Intrumentation class.

class ContactsFilterInstrumentation extends Instrumentation {   @Override       public void onCreate(Bundle arguments) {  super.onCreate(arguments); start();   }    @Override    public void onStart() {  super.onStart();  Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClassName(getTargetContext(), "com.android.phone.Dialer"); Activity activity = startActivitySync(intent);  Log.i("ContactsFilterInstrumentation", "Started: " + activity); sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_M)); sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_M)); sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A)); sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_A)); waitForIdleSync(); Log.i("ContactsFilterInstrumentation", "Done!"); finish(Activity.RESULT_OK, null); } } 

Can Any help me out. Thanks in Advance.

回答1:

Directory structure should be:

src   package.x.y.z.test       MainTest.java       CustomInstrumentationRunner.java 

Then in the AndroidManifest.xml, set

<manifest package="package.x.y.z" ...  <instrumentation         android:name="package.x.y.z.test.CustomInstrumentationRunner" 

Invoke the above package with the command line:

adb shell am instrumentation -w package.x.y.z/package.x.y.z.test.CustomInstrumentationRunner 


回答2:

An Instrumentation implementation is described to the system through an AndroidManifest.xml's <instrumentation> tag.



回答3:

I solved this problem by doing the following:

  1. Use a upper-level package name in the manifest:

  2. Implement the test packages one level down: Java file 1:

    package com.xxx.yyy.zzz.ptest.onlylogin;

Java file 2:

package com.xxx.yyy.zzz.ptest.register; 
  1. Specify the command line like the following:

    ...



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!