InstrumentationTestRunner Class

Definition

An Instrumentation that runs various types of junit.framework.TestCases against an Android package (application).

[Android.Runtime.Register("android/test/InstrumentationTestRunner", DoNotGenerateAcw=true)]
public class InstrumentationTestRunner : Android.App.Instrumentation
[<Android.Runtime.Register("android/test/InstrumentationTestRunner", DoNotGenerateAcw=true)>]
type InstrumentationTestRunner = class
    inherit Instrumentation
Inheritance
InstrumentationTestRunner
Attributes

Remarks

An Instrumentation that runs various types of junit.framework.TestCases against an Android package (application).

<div class="special reference"> <h3>Developer Guides</h3>

For more information about application testing, read the Testing developer guide.

</div>

<h3>Typical Usage</h3> <ol> <li>Write junit.framework.TestCases that perform unit, functional, or performance tests against the classes in your package. Typically these are subclassed from: <ul><li>android.test.ActivityInstrumentationTestCase2</li> <li>android.test.ActivityUnitTestCase</li> <li>android.test.AndroidTestCase</li> <li>android.test.ApplicationTestCase</li> <li>android.test.InstrumentationTestCase</li> <li>android.test.ProviderTestCase</li> <li>android.test.ServiceTestCase</li> <li>android.test.SingleLaunchActivityTestCase</li></ul> <li>Set the android:targetPackage attribute of the &lt;instrumentation&gt; element in the test package's manifest. You should set the attribute value to the package name of the target application under test. <li>Run the instrumentation using "adb shell am instrument -w", with no optional arguments, to run all tests (except performance tests). <li>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 android.test.InstrumentationTestCase. <li>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 android.test.InstrumentationTestCase (and are not performance tests). <li>Run the instrumentation using "adb shell am instrument -w", with the argument '-e class' set to run an individual junit.framework.TestCase. </ol> <p/> <b>Running all tests:</b> adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Running all small tests:</b> adb shell am instrument -w -e size small com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Running all medium tests:</b> adb shell am instrument -w -e size medium com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Running all large tests:</b> adb shell am instrument -w -e size large com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Filter test run to tests with given annotation:</b> adb shell am instrument -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.g. "-e size large -e annotation com.android.foo.MyAnnotation" will run only tests with both the LargeTest and "com.android.foo.MyAnnotation" annotations. <p/> <b>Filter test run to tests without given annotation:</b> adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Running a single testcase:</b> adb shell am instrument -w -e class com.android.foo.FooTest com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Running a single test:</b> adb shell am instrument -w -e class com.android.foo.FooTest#testFoo com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Running multiple tests:</b> adb shell am instrument -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Running all tests in a java package:</b> adb shell am instrument -w -e package com.android.foo.subpkg com.android.foo/android.test.InstrumentationTestRunner <p/> <b>Including performance tests:</b> adb shell am instrument -w -e perf true com.android.foo/android.test.InstrumentationTestRunner <p/> <b>To debug your tests, set a break point in your code and pass:</b> -e debug true <p/> <b>To run in 'log only' mode</b> -e log true This option will load and iterate through all test classes and methods, but will bypass actual test execution. Useful for quickly obtaining info on the tests to be executed by an instrumentation command. <p/> <b>To generate EMMA code coverage:</b> -e coverage true Note: this requires an emma instrumented build. By default, the code coverage results file will be saved in a /data/<app>/coverage.ec file, unless overridden by coverageFile flag (see below) <p/> <b> To specify EMMA code coverage results file path:</b> -e coverageFile /sdcard/myFile.ec <br/> in addition to the other arguments.

This member is deprecated. Use AndroidJUnitRunner instead. New tests should be written using the Android Testing Support Library.

Java documentation for android.test.InstrumentationTestRunner.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

InstrumentationTestRunner()
InstrumentationTestRunner(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

ReportKeyIdentifier

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the class that is writing the report.

(Inherited from Instrumentation)
ReportKeyNameClass

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the name of the current test class.

ReportKeyNameTest

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the name of the current test.

ReportKeyNumCurrent

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the sequence number of the current test.

ReportKeyNumTotal

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the total number of tests that are being run.

ReportKeyStack

If included in the status bundle sent to an IInstrumentationWatcher, this key identifies a stack trace describing an error or failure.

ReportKeyStreamresult

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies a string which can simply be printed to the output stream.

(Inherited from Instrumentation)
ReportValueId

This value, if stored with key android.app.Instrumentation#REPORT_KEY_IDENTIFIER, identifies InstrumentationTestRunner as the source of the report.

Properties

AllocCounts

Returns a bundle with the current results from the allocation counting.

(Inherited from Instrumentation)
Arguments

Get the arguments passed to this instrumentation.

BinderCounts

Returns a bundle with the counts for various binder counts for this process.

(Inherited from Instrumentation)
Class

Returns the runtime class of this Object.

(Inherited from Object)
ComponentName

Returns complete component name of this instrumentation.

(Inherited from Instrumentation)
Context

Return the Context of this instrumentation's package.

(Inherited from Instrumentation)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsProfiling

Check whether this instrumentation was started with profiling enabled.

(Inherited from Instrumentation)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
Loader

Override this to provide access to the class loader of your package.

PeerReference (Inherited from Object)
ProcessName

Return the name of the process this instrumentation is running in.

(Inherited from Instrumentation)
TargetContext

Return a Context for the target application being instrumented.

(Inherited from Instrumentation)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

UiAutomation

Gets the UiAutomation instance with no flags set.

(Inherited from Instrumentation)

Methods

AcquireLooperManager(Looper)

Takes control of the execution of messages on the specified looper until TestLooperManager#release is called.

(Inherited from Instrumentation)
AddMonitor(Instrumentation+ActivityMonitor)

Add a new ActivityMonitor that will be checked whenever an activity is started.

(Inherited from Instrumentation)
AddMonitor(IntentFilter, Instrumentation+ActivityResult, Boolean)

Add a new ActivityMonitor that will be checked whenever an activity is started.

(Inherited from Instrumentation)
AddMonitor(String, Instrumentation+ActivityResult, Boolean)

Add a new ActivityMonitor that will be checked whenever an activity is started.

(Inherited from Instrumentation)
AddResults(Bundle)

Report some results in the middle of instrumentation execution.

(Inherited from Instrumentation)
CallActivityOnCreate(Activity, Bundle)

Perform calling of an activity's Activity#onCreate method.

(Inherited from Instrumentation)
CallActivityOnCreate(Activity, Bundle, PersistableBundle)

Perform calling of an activity's Activity#onCreate method.

(Inherited from Instrumentation)
CallActivityOnDestroy(Activity) (Inherited from Instrumentation)
CallActivityOnNewIntent(Activity, Intent)

Perform calling of an activity's Activity#onNewIntent method.

(Inherited from Instrumentation)
CallActivityOnPause(Activity)

Perform calling of an activity's Activity#onPause method.

(Inherited from Instrumentation)
CallActivityOnPictureInPictureRequested(Activity)

Perform calling of an activity's Activity#onPictureInPictureRequested method.

(Inherited from Instrumentation)
CallActivityOnPostCreate(Activity, Bundle)

Perform calling of an activity's Activity#onPostCreate method.

(Inherited from Instrumentation)
CallActivityOnPostCreate(Activity, Bundle, PersistableBundle)

Perform calling of an activity's Activity#onPostCreate method.

(Inherited from Instrumentation)
CallActivityOnRestart(Activity)

Perform calling of an activity's Activity#onRestart method.

(Inherited from Instrumentation)
CallActivityOnRestoreInstanceState(Activity, Bundle)

Perform calling of an activity's Activity#onRestoreInstanceState method.

(Inherited from Instrumentation)
CallActivityOnRestoreInstanceState(Activity, Bundle, PersistableBundle)

Perform calling of an activity's Activity#onRestoreInstanceState method.

(Inherited from Instrumentation)
CallActivityOnResume(Activity)

Perform calling of an activity's Activity#onResume method.

(Inherited from Instrumentation)
CallActivityOnSaveInstanceState(Activity, Bundle)

Perform calling of an activity's Activity#onSaveInstanceState method.

(Inherited from Instrumentation)
CallActivityOnSaveInstanceState(Activity, Bundle, PersistableBundle)

Perform calling of an activity's Activity#onSaveInstanceState method.

(Inherited from Instrumentation)
CallActivityOnStart(Activity)

Perform calling of an activity's Activity#onStart method.

(Inherited from Instrumentation)
CallActivityOnStop(Activity)

Perform calling of an activity's Activity#onStop method.

(Inherited from Instrumentation)
CallActivityOnUserLeaving(Activity)

Perform calling of an activity's Activity#onUserLeaveHint method.

(Inherited from Instrumentation)
CallApplicationOnCreate(Application)

Perform calling of the application's Application#onCreate method.

(Inherited from Instrumentation)
CheckMonitorHit(Instrumentation+ActivityMonitor, Int32)

Test whether an existing ActivityMonitor has been hit.

(Inherited from Instrumentation)
Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
EndPerformanceSnapshot() (Inherited from Instrumentation)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Finish(Result, Bundle)

Terminate instrumentation of the application.

(Inherited from Instrumentation)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetUiAutomation(UiAutomationFlags)

Gets the UiAutomation instance with flags set.

(Inherited from Instrumentation)
InvokeContextMenuAction(Activity, Int32, MenuPerformFlags)

Show the context menu for the currently focused view and executes a particular context menu item.

(Inherited from Instrumentation)
InvokeMenuActionSync(Activity, Int32, MenuPerformFlags)

Execute a particular menu item.

(Inherited from Instrumentation)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
NewActivity(Class, Context, IBinder, Application, Intent, ActivityInfo, ICharSequence, Activity, String, Object)

Perform instantiation of an Activity object.

(Inherited from Instrumentation)
NewActivity(Class, Context, IBinder, Application, Intent, ActivityInfo, String, Activity, String, Object)

Perform instantiation of an Activity object.

(Inherited from Instrumentation)
NewActivity(ClassLoader, String, Intent)

Perform instantiation of the process's Activity object.

(Inherited from Instrumentation)
NewApplication(ClassLoader, String, Context)

Perform instantiation of the process's Application object.

(Inherited from Instrumentation)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
OnCreate(Bundle)

Called when the instrumentation is starting, before any application code has been loaded.

(Inherited from Instrumentation)
OnDestroy()

Called when the instrumented application is stopping, after all of the normal application cleanup has occurred.

(Inherited from Instrumentation)
OnException(Object, Throwable)

This is called whenever the system captures an unhandled exception that was thrown by the application.

(Inherited from Instrumentation)
OnStart()

Method where the instrumentation thread enters execution.

(Inherited from Instrumentation)
RemoveMonitor(Instrumentation+ActivityMonitor)

Remove an ActivityMonitor that was previously added with #addMonitor.

(Inherited from Instrumentation)
ResetInTouchMode()

Resets the #setInTouchMode touch mode to the device default.

(Inherited from Instrumentation)
RunOnMainSync(Action) (Inherited from Instrumentation)
RunOnMainSync(IRunnable)

Execute a call on the application's main thread, blocking until it is complete.

(Inherited from Instrumentation)
SendCharacterSync(Keycode)

Sends up and down key events with the given key code to the currently focused window, and waits for it to be processed.

(Inherited from Instrumentation)
SendKeyDownUpSync(Keycode)

Sends up and down key events with the given key code to the currently focused window, and waits for it to be processed.

(Inherited from Instrumentation)
SendKeySync(KeyEvent)

Sends a key event to the currently focused window, and waits for it to be processed.

(Inherited from Instrumentation)
SendPointerSync(MotionEvent)

Dispatches a pointer event into a window owned by the instrumented application, and waits for it to be processed.

(Inherited from Instrumentation)
SendStatus(Result, Bundle)

Provide a status report about the application.

(Inherited from Instrumentation)
SendStringSync(String)

Sends the key events that result in the given text being typed into the currently focused window, and waits for it to be processed.

(Inherited from Instrumentation)
SendTrackballEventSync(MotionEvent)

Dispatches a trackball event into the currently focused window, and waits for it to be processed.

(Inherited from Instrumentation)
SetAutomaticPerformanceSnapshots() (Inherited from Instrumentation)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetInTouchMode(Boolean)

Force the global system in or out of touch mode.

(Inherited from Instrumentation)
Start()

Create and start a new thread in which to run instrumentation.

(Inherited from Instrumentation)
StartActivitySync(Intent)

Start a new activity and wait for it to begin running before returning.

(Inherited from Instrumentation)
StartActivitySync(Intent, Bundle)

Start a new activity and wait for it to begin running before returning.

(Inherited from Instrumentation)
StartAllocCounting() (Inherited from Instrumentation)
StartPerformanceSnapshot() (Inherited from Instrumentation)
StartProfiling()

This method will start profiling if isProfiling() returns true.

(Inherited from Instrumentation)
StopAllocCounting() (Inherited from Instrumentation)
StopProfiling()

Stops profiling if isProfiling() returns true.

(Inherited from Instrumentation)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
WaitForIdle(Action) (Inherited from Instrumentation)
WaitForIdle(IRunnable)

Schedule a callback for when the application's main thread goes idle (has no more events to process).

(Inherited from Instrumentation)
WaitForIdleSync()

Synchronously wait for the application to be idle.

(Inherited from Instrumentation)
WaitForMonitor(Instrumentation+ActivityMonitor)

Wait for an existing ActivityMonitor to be hit.

(Inherited from Instrumentation)
WaitForMonitorWithTimeout(Instrumentation+ActivityMonitor, Int64)

Wait for an existing ActivityMonitor to be hit till the timeout expires.

(Inherited from Instrumentation)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to