安卓清单文件Instrumentation

6

我有一个安卓测试项目,用于测试我的安卓项目。在安卓测试项目的清单文件中,我有一个关于仪器化的条目,它看起来像这样:

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

我很好奇这个条目的目的是什么,特别是android:targetPackage="com.company.android"的用途是什么。我之所以问,是因为我重构了旧项目,并把类放在不同的包中,所以我很想知道我需要更新这个值到什么位置... 它应该指向扩展android.app.Application的类所在的包吗?

2个回答

7

它应该指向哪个包?活动所在的地方还是应用程序所在的地方?顺便说一句,我喜欢这个用户名。 - James Oravec
1
通常活动所在的位置和应用程序所在的位置是相同的。这在我测试应用程序时也是一样的。我想它想知道应用程序包,因为至少需要在查找活动之前访问应用程序。 - Shellum
编译中...我们看看是否成功 :) - James Oravec
太好了!让我走出了困境...仍然有问题,但那给了我所需的东西! - James Oravec

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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接