语言

InstrumentationTestRunner 类

定义

注意

This class is obsoleted in this android platform

Instrumentation针对 Android 包(应用程序)运行各种类型的 junit.framework.TestCases。

[Android.Runtime.Register("android/test/InstrumentationTestRunner", DoNotGenerateAcw=true)]
[System.Obsolete("This class is obsoleted in this android platform")]
public class InstrumentationTestRunner : Android.App.Instrumentation
[<Android.Runtime.Register("android/test/InstrumentationTestRunner", DoNotGenerateAcw=true)>]
[<System.Obsolete("This class is obsoleted in this android platform")>]
type InstrumentationTestRunner = class
    inherit Instrumentation
继承
InstrumentationTestRunner
特性

注解

Instrumentation针对 Android 包(应用程序)运行各种类型的 junit.framework.TestCases。

<div class=“special reference”><h3>Developer Guides</h3>

有关应用程序测试的详细信息,请阅读 测试 开发人员指南。

</div>

<h3>典型用法</h3><ol><li>Write junit.framework.TestCases,用于针对包中的类执行单元、功能或性能测试。 通常,这些是从:<ul><li>android.test.ActivityInstrumentationTestCase2</li><>android.test.ActivityUnitTestCase</><>android.test.AndroidTestCase<><>android.test.ApplicationTestCase<li/li/><>android.test.InstrumentationTestCase<li/><>android.test.ProviderTestCase<><>android.test.ServiceTestCase<li/><>android.test.SingleLaunchActivityTestCase<li/li></ul><li>Set the android:targetPackage attribute <instrumentation> of the element in the test package's manifest. 应将属性值设置为正在测试的目标应用程序的包名称。 <li>使用“adb shell am instrumentation -w”(没有可选参数)运行检测,以运行所有测试(性能测试除外)。 <li>使用“adb shell am instrumentation -w”运行检测,并将参数“-e func true”用于运行所有功能测试。 这些测试派生自 android.test.InstrumentationTestCase. <li>使用“adb shell am instrumentation -w”运行检测,参数“-e unit true”运行所有单元测试。 这些测试 不派生自 android.test.InstrumentationTestCase (不是性能测试)。 <li>使用“adb shell am instrumentation -w”运行检测,并将参数“-e 类”设置为运行个人 junit.framework.TestCase。 </ol><p/>运行所有测试: adb shell am instrumentation -w com.android.foo/android.test.InstrumentationTestRunner <p/>Running all small tests: adb shell am instrumentation -w -e size small com.android.foo/android.test.InstrumentationTestRunner <p/>Running all medium tests: adb shell am instrumentation -w -e size medium com.android.foo/android.test.InstrumentationTestRunner <p/>Running all large tests: adb shell am instruments -w -e size large com.android.foo/android.test.InstrumentationTestRunner <p/>Filter test run to test with given annotation: adb shell am instrumentation -w -e annotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner <p/> If used with other options, the resulting test run will contain the union of the two options. 例如,“-e 大小大 -e 批注 com.android.foo.MyAnnotation”将仅运行包含 LargeTest “com.android.foo.MyAnnotation”批注的测试。 <p/><b>筛选器测试运行到没有给定注释的测试:</b> adb shell am instrumentation -w -e notAnnotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner <p/>Running a single testcase: adb shell am instrumentation -w -e class com.android.foo.Foo/android.test.InstrumentationTestRunner <p/>Running a single test:adb shell am instrumentation -w -e class com.android.foo.FooTest#testFoo com.android.foo/android.test.InstrumentationTestRunner <p/>Running multiple tests: adb shell am instrumentation -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/android.test.InstrumentationTestRunner <p/>Running all tests in a java package: adb shell am instrumentation -w -e package com.android.foo.subpkg com.android.foo/android.test.InstrumentationTestRunner <p/>包括性能测试:adb shell am instrumentation -w -e perf true com.android.foo/android.test.InstrumentationTestRunner <p/To debug your tests, set a break point in your code and pass: -e debug true <p/>>To run in 'log only' mode -e log true. 可用于快速获取检测命令要执行的测试的信息。 <p/>若要生成 EMMA 代码覆盖率:-e 覆盖率 为 true 注意:这需要 emma 检测生成。 默认情况下,代码覆盖率结果文件将保存在 /data/<app>/coverage.ec 文件中,除非由 coverageFile 标志重写(请参阅下文) <p/> 若要指定 EMMA 代码覆盖率结果文件路径: -e coverageFile /sdcard/myFile.ec <br/> 以及其他参数。

此成员已弃用。 请改用 AndroidJUnitRunner 。 应使用 Android 测试支持库编写新测试。

Java文档android.test.InstrumentationTestRunner。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

构造函数

名称 说明
InstrumentationTestRunner()
已过时.

初始化 InstrumentationTestRunner 类的新实例。

InstrumentationTestRunner(IntPtr, JniHandleOwnership)
已过时.

创建 JNI 对象的托管表示形式时使用的构造函数;由运行时调用。

字段

名称 说明
ReportKeyIdentifier
已过时.

如果包含在发送到 IInstrumentationWatcher 的状态或最终捆绑包中,则此键标识正在写入报告的类。

(继承自 Instrumentation)
ReportKeyNameClass
已过时.

如果包含在发送到 IInstrumentationWatcher 的状态或最终捆绑包中,则此键标识当前测试类的名称。

ReportKeyNameTest
已过时.

如果包含在发送到 IInstrumentationWatcher 的状态或最终捆绑包中,则此密钥标识当前测试的名称。

ReportKeyNumCurrent
已过时.

如果包含在发送到 IInstrumentationWatcher 的状态或最终捆绑包中,则此键标识当前测试的序列号。

ReportKeyNumTotal
已过时.

如果包含在发送到 IInstrumentationWatcher 的状态或最终捆绑包中,则此密钥标识要运行的测试总数。

ReportKeyStack
已过时.

如果包含在发送到 IInstrumentationWatcher 的状态捆绑包中,则此密钥标识描述错误或失败的堆栈跟踪。

ReportKeyStreamresult
已过时.

如果包含在发送到 IInstrumentationWatcher 的状态或最终捆绑包中,则此键标识一个字符串,该字符串只需打印到输出流即可。

(继承自 Instrumentation)
ReportValueId
已过时.

此值(如果使用键 android.app.Instrumentation#REPORT_KEY_IDENTIFIER存储)将 InstrumentationTestRunner 标识为报表的源。

属性

名称 说明
AllocCounts
已过时.

返回分配计数中当前结果的捆绑包。

(继承自 Instrumentation)
Arguments
已过时.

获取传递给此检测的参数。

BinderCounts
已过时.

返回一个捆绑包,其中包含此过程的各种联编程序计数。

(继承自 Instrumentation)
Class
已过时.

返回此 Object的运行时类。

(继承自 Object)
ComponentName
已过时.

返回此检测的完整组件名称。

(继承自 Instrumentation)
Context
已过时.

返回此检测包的上下文。

(继承自 Instrumentation)
Handle
已过时.

基础 Android 实例的句柄。

(继承自 Object)
IsProfiling
已过时.

检查是否已启动此检测,并启用分析。

(继承自 Instrumentation)
JniIdentityHashCode
已过时.

获取互操作运行时分配给此Java对等的标识哈希代码。

(继承自 Object)
JniManagedPeerState
已过时.

获取运行时上次分配的状态标志。

(继承自 JavaObject)
JniPeerMembers
已过时.

获取用于访问此Java绑定成员的 JNI 元数据。

Loader
已过时.

重写此选项以提供对包的类加载程序的访问权限。

PeerReference
已过时.

获取此Java对等方的 JNI 对象引用。

(继承自 Object)
ProcessName
已过时.

返回运行此检测的进程的名称。

(继承自 Instrumentation)
TargetContext
已过时.

返回要检测的目标应用程序的上下文。

(继承自 Instrumentation)
ThresholdClass
已过时.

此 API 支持 Mono for Android 基础结构,不打算直接从代码使用。

ThresholdType
已过时.

此 API 支持 Mono for Android 基础结构,不打算直接从代码使用。

UiAutomation
已过时.

UiAutomation获取未设置标志的实例。

(继承自 Instrumentation)

方法

名称 说明
AcquireLooperManager(Looper)
已过时.

控制在指定的循环器上执行消息,直到 TestLooperManager#release 调用为止。

(继承自 Instrumentation)
AddMonitor(Instrumentation+ActivityMonitor)
已过时.

添加一个新的 ActivityMonitor,每当启动活动时都会进行检查。

(继承自 Instrumentation)
AddMonitor(IntentFilter, Instrumentation+ActivityResult, Boolean)
已过时.

addMonitor(ActivityMonitor)的便利包装器,可为你创建匹配 ActivityMonitor 的意向筛选器并返回它。

(继承自 Instrumentation)
AddMonitor(String, Instrumentation+ActivityResult, Boolean)
已过时.

addMonitor(ActivityMonitor)的便利包装器,可为你创建一个匹配 ActivityMonitor 的类并返回它。

(继承自 Instrumentation)
AddResults(Bundle)
已过时.

在检测执行期间报告一些结果。

(继承自 Instrumentation)
CallActivityOnCreate(Activity, Bundle, PersistableBundle)
已过时.

执行对活动方法的 Activity#onCreate 调用。

(继承自 Instrumentation)
CallActivityOnCreate(Activity, Bundle)
已过时.

执行对活动方法的 Activity#onCreate 调用。

(继承自 Instrumentation)
CallActivityOnDestroy(Activity)
已过时.

通过活动的内部销毁例程调用活动的销毁生命周期。

(继承自 Instrumentation)
CallActivityOnNewIntent(Activity, Intent, ComponentCaller)
已过时.

同样 #callActivityOnNewIntent(Activity, Intent),但对于 ComponentCaller 与发送意向的应用关联的实例,还有一个额外的参数。

(继承自 Instrumentation)
CallActivityOnNewIntent(Activity, Intent)
已过时.

执行对活动方法的 Activity#onNewIntent 调用。

(继承自 Instrumentation)
CallActivityOnPause(Activity)
已过时.

执行对活动方法的 Activity#onPause 调用。

(继承自 Instrumentation)
CallActivityOnPictureInPictureRequested(Activity)
已过时.

执行对活动方法的 Activity#onPictureInPictureRequested 调用。

(继承自 Instrumentation)
CallActivityOnPostCreate(Activity, Bundle, PersistableBundle)
已过时.

执行对活动方法的 Activity#onPostCreate 调用。

(继承自 Instrumentation)
CallActivityOnPostCreate(Activity, Bundle)
已过时.

执行对活动方法的 Activity#onPostCreate 调用。

(继承自 Instrumentation)
CallActivityOnRestart(Activity)
已过时.

执行对活动方法的 Activity#onRestart 调用。

(继承自 Instrumentation)
CallActivityOnRestoreInstanceState(Activity, Bundle, PersistableBundle)
已过时.

执行对活动方法的 Activity#onRestoreInstanceState 调用。

(继承自 Instrumentation)
CallActivityOnRestoreInstanceState(Activity, Bundle)
已过时.

执行对活动方法的 Activity#onRestoreInstanceState 调用。

(继承自 Instrumentation)
CallActivityOnResume(Activity)
已过时.

执行对活动方法的 Activity#onResume 调用。

(继承自 Instrumentation)
CallActivityOnSaveInstanceState(Activity, Bundle, PersistableBundle)
已过时.

执行对活动方法的 Activity#onSaveInstanceState 调用。

(继承自 Instrumentation)
CallActivityOnSaveInstanceState(Activity, Bundle)
已过时.

执行对活动方法的 Activity#onSaveInstanceState 调用。

(继承自 Instrumentation)
CallActivityOnStart(Activity)
已过时.

执行对活动方法的 Activity#onStart 调用。

(继承自 Instrumentation)
CallActivityOnStop(Activity)
已过时.

执行对活动方法的 Activity#onStop 调用。

(继承自 Instrumentation)
CallActivityOnUserLeaving(Activity)
已过时.

执行对活动方法的 Activity#onUserLeaveHint 调用。

(继承自 Instrumentation)
CallApplicationOnCreate(Application)
已过时.

执行对应用程序方法的 Application#onCreate 调用。

(继承自 Instrumentation)
CheckMonitorHit(Instrumentation+ActivityMonitor, Int32)
已过时.

测试是否已命中现有 ActivityMonitor。

(继承自 Instrumentation)
Clone()
已过时.

创建并返回此对象的副本。

(继承自 Object)
Construct(JniObjectReference, JniObjectReferenceOptions)
已过时.

将此对等方的构造委托给运行时的值管理器。

(继承自 JavaObject)
Dispose()
已过时.

释放此Java对等方持有的资源。

(继承自 Object)
Dispose(Boolean)
已过时.

释放此Java对等方持有的资源。

(继承自 Object)
DisposeUnlessReferenced()
已过时.

要求值管理器释放此对等方,除非其映射保留此相同的托管实例。

(继承自 JavaObject)
EndPerformanceSnapshot()
已过时.

结束配置的收集器的快照,并在禁用分析时存储其指标。

(继承自 Instrumentation)
Equals(Object)
已过时.

测试另一个托管对等方是否引用同一Java对象。

(继承自 JavaObject)
Equals(Object)
已过时.

指示其他对象是否“等于”此对象。

(继承自 Object)
Finish(Result, Bundle)
已过时.

终止应用程序的检测。

(继承自 Instrumentation)
GetHashCode()
已过时.

返回对象的哈希代码值。

(继承自 Object)
GetUiAutomation(UiAutomationFlags)
已过时.

UiAutomation获取设置了标志的实例。

(继承自 Instrumentation)
InvokeContextMenuAction(Activity, Int32, MenuPerformFlags)
已过时.

显示当前聚焦视图的上下文菜单,并执行特定的上下文菜单项。

(继承自 Instrumentation)
InvokeMenuActionSync(Activity, Int32, MenuPerformFlags)
已过时.

执行特定菜单项。

(继承自 Instrumentation)
JavaFinalize()
已过时.

当垃圾回收确定不再引用该对象时,由对象上的垃圾回收器调用。

(继承自 Object)
NewActivity(Class, Context, IBinder, Application, Intent, ActivityInfo, ICharSequence, Activity, String, Object)
已过时.

执行对象的实例化 Activity 。

(继承自 Instrumentation)
NewActivity(Class, Context, IBinder, Application, Intent, ActivityInfo, String, Activity, String, Object)
已过时.

执行对象的实例化 Activity 。

(继承自 Instrumentation)
NewActivity(ClassLoader, String, Intent)
已过时.

执行进程的 Activity 对象的实例化。

(继承自 Instrumentation)
NewApplication(ClassLoader, String, Context)
已过时.

执行进程的 Application 对象的实例化。

(继承自 Instrumentation)
Notify()
已过时.

唤醒正在等待此对象的监视器的单个线程。

(继承自 Object)
NotifyAll()
已过时.

唤醒正在等待此对象的监视器的所有线程。

(继承自 Object)
OnCreate(Bundle)
已过时.

在启动检测时调用,然后加载任何应用程序代码。

(继承自 Instrumentation)
OnDestroy()
已过时.

在检测到的应用程序停止时调用,在发生所有正常的应用程序清理后。

(继承自 Instrumentation)
OnException(Object, Throwable)
已过时.

每当系统捕获应用程序引发的未经处理的异常时,都会调用此异常。

(继承自 Instrumentation)
OnStart()
已过时.

检测线程进入执行的方法。

(继承自 Instrumentation)
RemoveMonitor(Instrumentation+ActivityMonitor)
已过时.

删除以前随 addMonitor(ActivityMonitor)一起添加的 ActivityMonitor。

(继承自 Instrumentation)
ResetInTouchMode()
已过时.

#setInTouchMode touch mode将重置为设备默认值。

(继承自 Instrumentation)
RunOnMainSync(Action)
已过时.

将操作发布到应用程序的主线程,并等待它完成。

(继承自 Instrumentation)
RunOnMainSync(IRunnable)
已过时.

对应用程序的主线程执行调用,直到它完成为止。

(继承自 Instrumentation)
SendCharacterSync(Keycode)
已过时.

将具有给定键代码的向上和向下键事件发送到当前焦点窗口,并等待处理它。

(继承自 Instrumentation)
SendKeyDownUpSync(Keycode)
已过时.

将具有给定键代码的向上和向下键事件发送到当前焦点窗口,并等待处理它。

(继承自 Instrumentation)
SendKeySync(KeyEvent)
已过时.

将键事件发送到当前聚焦的窗口,并等待处理它。

(继承自 Instrumentation)
SendPointerSync(MotionEvent)
已过时.

将指针事件调度到受检测应用程序拥有的窗口中,并等待处理它。

(继承自 Instrumentation)
SendStatus(Result, Bundle)
已过时.

提供有关应用程序的状态报告。

(继承自 Instrumentation)
SendStringSync(String)
已过时.

发送导致给定文本被键入到当前焦点窗口中的关键事件,并等待处理它。

(继承自 Instrumentation)
SendTrackballEventSync(MotionEvent)
已过时.

将轨迹球事件调度到当前聚焦的窗口中,并等待处理它。

(继承自 Instrumentation)
SetAutomaticPerformanceSnapshots()
已过时.

启用自动性能快照并创建其收集器。

(继承自 Instrumentation)
SetHandle(IntPtr, JniHandleOwnership)
已过时.

设置 Handle 属性。

(继承自 Object)
SetInTouchMode(Boolean)
已过时.

强制全局系统处于或脱离接触模式。

(继承自 Instrumentation)
SetPeerReference(JniObjectReference, JniObjectReferenceOptions)
已过时.

在不创建 JNI 引用副本的情况下,将引用值存储在控制块中。

(继承自 JavaObject)
Start()
已过时.

创建并启动运行检测的新线程。

(继承自 Instrumentation)
StartActivitySync(Intent, Bundle)
已过时.

启动一个新活动,并等待它开始运行,然后再返回。

(继承自 Instrumentation)
StartActivitySync(Intent)
已过时.

启动一个新活动,并等待它开始运行,然后再返回。

(继承自 Instrumentation)
StartAllocCounting()
已过时.

在垃圾回收、最终化和计数器重置后请求旧分配计数。

(继承自 Instrumentation)
StartPerformanceSnapshot()
已过时.

禁用分析时,在配置的性能收集器上开始快照。

(继承自 Instrumentation)
StartProfiling()
已过时.

如果 isProfiling() 返回 true,此方法将开始分析。

(继承自 Instrumentation)
StopAllocCounting()
已过时.

旧分配计数在垃圾回收和最终化后停止的请求。

(继承自 Instrumentation)
StopProfiling()
已过时.

如果 isProfiling() 返回 true,则停止分析。

(继承自 Instrumentation)
ToArray<T>()
已过时.

从此Java数组包装器创建托管数组。

(继承自 Object)
ToString()
已过时.

返回对象的字符串表示形式。

(继承自 Object)
UnregisterFromRuntime()
已过时.

从互操作运行时取消注册此Java对等。

(继承自 Object)
Wait()
已过时.

导致当前线程等待,直到它被唤醒,通常是通过 通知 或 中断。

(继承自 Object)
Wait(Int64, Int32)
已过时.

使当前线程等待直到唤醒,通常是通过 通知 或 中断,或直到经过一定数量的实时。

(继承自 Object)
Wait(Int64)
已过时.

使当前线程等待直到唤醒,通常是通过 通知 或 中断,或直到经过一定数量的实时。

(继承自 Object)
WaitForIdle(Action)
已过时.

计划主消息队列的下一个空闲期的操作,而无需等待它。

(继承自 Instrumentation)
WaitForIdle(IRunnable)
已过时.

计划应用程序的主线程空闲时间的回调(没有要处理的事件)。

(继承自 Instrumentation)
WaitForIdleSync()
已过时.

同步等待应用程序空闲。

(继承自 Instrumentation)
WaitForMonitor(Instrumentation+ActivityMonitor)
已过时.

等待现有 ActivityMonitor 命中。

(继承自 Instrumentation)
WaitForMonitorWithTimeout(Instrumentation+ActivityMonitor, Int64)
已过时.

等待现有 ActivityMonitor 命中,直到超时过期。

(继承自 Instrumentation)

显式接口实现

名称 说明
IJavaPeerable.Disposed()
已过时.

将此对等方标记为已释放,并将disposing调用Dispose设置为 true.

(继承自 JavaObject)
IJavaPeerable.Finalized()
已过时.

将此对等方标记为已释放,并将disposing调用Dispose设置为 false.

(继承自 JavaObject)
IJavaPeerable.JniObjectReferenceControlBlock
已过时.

获取此对等方使用的本机控制块指针。

(继承自 JavaObject)
IJavaPeerable.SetJniIdentityHashCode(Int32)
已过时.

存储运行时提供的标识哈希代码。

(继承自 JavaObject)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)
已过时.

替换存储的托管对等状态标志。

(继承自 JavaObject)
IJavaPeerable.SetPeerReference(JniObjectReference)
已过时.

更新对等引用,并在引用无效时释放已释放的对等方控制块。

(继承自 JavaObject)

扩展方法

名称 说明
GetJniTypeName(IJavaPeerable)
已过时.

获取实例 self类型的 JNI 名称。

JavaAs<TResult>(IJavaPeerable)
已过时.

尝试强制self键入TResult,检查强制是否在Java端有效。

JavaCast<TResult>(IJavaObject)
已过时.

执行 Android 运行时检查的类型转换。

JavaCast<TResult>(IJavaObject)
已过时.

重复使用兼容的托管对等,或获取请求类型的包装器。

TryJavaCast<TResult>(IJavaPeerable, TResult)
已过时.

尝试强制self键入TResult,检查强制是否在Java端有效。

适用于