6

我有一个android test project设置来测试我的android project. 在android test project的清单中,我有一个instrumentation. 看起来像:

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

我很好奇这个条目的意义是什么,特别是它的目的android:targetPackage="com.company.android"是什么。我问,因为我重构了旧项目并将类放入不同的包中,所以我很好奇我需要将这个值更新为...是否应该指向扩展类所在的包android.app.Application

4

2 回答 2

7

它告诉构建系统在哪里访问您要测试的实际项目。

这是必要的,因为您需要访问所有活动和课程,而无需额外的副本。

有关它的信息分散在:http: //developer.android.com/tools/testing/testing_android.html

于 2013-04-16T22:48:16.750 回答
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.
于 2013-04-16T22:49:55.630 回答