2013-04-16 42 views
3

我有一個android test project設置來測試我的android project。在android test project的清單中,我有一個instrumentation的條目。它看起來像:Android Manifest Instrumentation

<instrumentation 
    android:name="android.test.InstrumentationTestRunner" 
    android:targetPackage="com.company.android" /> 

我很好奇這個入口點是什麼,particuarly什麼android:targetPackage="com.company.android"目的是爲了。我問,因爲我重構了舊項目,並將類放入不同的包中,所以我很好奇我需要更新此值......是否指向延伸android.app.Application的類位於的包?

回答

4

它告訴構建系統在哪裏訪問您要測試的實際項目。

這是必要的,因爲您需要訪問所有活動和課程而無需額外拷貝。

信息關於它在散落:http://developer.android.com/tools/testing/testing_android.html

+0

它應該是指向哪個包?活動在哪裏,或者申請是在哪裏?附:愛手柄。 –

+1

通常活動的地方和應用程序的位置是相同的。在我的應用程序中,我也有相同的測試應用程序。我想它是想知道應用程序包,因爲至少它需要在查找活動之前訪問應用程序。 – Shellum

+0

編譯...我們會看看是否是這種情況:) –

1

InstrumentationTestRunner是你用來編寫Android的單元測試。

從文檔:

Typical Usage 

Write TestCases that perform unit, functional, or performance tests against the classes in your package. 
Typically these are subclassed from: 

ActivityInstrumentationTestCase2 
ActivityUnitTestCase 
AndroidTestCase 
ApplicationTestCase 
InstrumentationTestCase 
ProviderTestCase 
ServiceTestCase 
SingleLaunchActivityTestCase 

In an appropriate AndroidManifest.xml, define the this instrumentation with the appropriate android:targetPackage set. 
Run the instrumentation using "adb shell am instrument -w", with no optional arguments, to run all tests (except performance tests). 
Run the instrumentation using "adb shell am instrument -w", with the argument '-e func true' to run all functional tests. These are tests that derive from InstrumentationTestCase. 
Run the instrumentation using "adb shell am instrument -w", with the argument '-e unit true' to run all unit tests. These are tests that do notderive from InstrumentationTestCase (and are not performance tests). 
Run the instrumentation using "adb shell am instrument -w", with the argument '-e class' set to run an individual TestCase.