2012-12-10 37 views
0

我想用測試應用程序中的Instrumentation接口來測試我的應用程序。 我有一個自定義活動,我的每一個活動延伸。在此我要開始的儀器來獲得程序的信息:儀器Android應用程序與啓動儀器

public class BxActivity extends Activity { 
@Override 
protected void onResume() { 
    super.onResume(); 
    ... 
    boolean instru = startInstrumentation(new ComponentName(BxActivity.this, InstrumentationRobot.class), null, null); 

恕我直言,這應該重新啓動與在InstrumentationRobot.class儀器代碼的應用程序。它在同一個Android項目和包中。

public class InstrumentationRobot extends Instrumentation { 
@Override 
public void onCreate(Bundle arguments) { 
    super.onCreate(arguments); 
    Log.v("InstrRobot", "Hello from Robot"); 
    start(); 
} 

我已經添加了儀器的清單如下:

<instrumentation 
     android:name="InstrumentationRobot" (class in the same pkg) 
     android:targetPackage="my.package.name" /> 
</application> 

這是我的儀表正確的清單代碼,所以我的小機器人打印出「你好」給我。

謝謝,soeren

回答

2

我找到了解決方案,並用正確的代碼更新了我的問題。 錯誤在清單文件中。

我刪除了

<uses-library android:name="android.test.runner" /> 

標籤和測試類的名稱不能以點開始,如果在測試類是在同一包和.apk文件的應用程序本身。

檢測標籤也必須是清單的直接子代。