positron
Class TestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by positron.TestCase
All Implemented Interfaces:
Test

public abstract class TestCase
extends TestCase


Field Summary
static int ALT
          KeyEvent.KEYCODE_ALT
static int BACK
          KeyEvent.KEYCODE_BACK
static int CALL
          KeyEvent.KEYCODE_CALL
static int CAMERA
          KeyEvent.KEYCODE_CAMERA
static int CAP
          KeyEvent.KEYCODE_CAP
static int CENTER
          KeyEvent.KEYCODE_DPAD_CENTER
static int CLEAR
          KeyEvent.KEYCODE_CLEAR
static int CLICK
          KeyEvent.KEYCODE_DPAD_CENTER
static int DOWN
          KeyEvent.KEYCODE_DPAD_DOWN
static int ENDCALL
          KeyEvent.KEYCODE_ENDCALL
static int ENVELOPE
          KeyEvent.KEYCODE_ENVELOPE
static int EXPLORER
          KeyEvent.KEYCODE_EXPLORER
static int HOME
          KeyEvent.KEYCODE_HOME
static int LEFT
          KeyEvent.KEYCODE_DPAD_LEFT
static int NEWLINE
          KeyEvent.KEYCODE_NEWLINE
static int NUM
          KeyEvent.KEYCODE_NUM
static int POWER
          KeyEvent.KEYCODE_POWER
static int RIGHT
          KeyEvent.KEYCODE_DPAD_RIGHT
static int SOFT_LEFT
          KeyEvent.KEYCODE_SOFT_LEFT
static int SOFT_RIGHT
          KeyEvent.KEYCODE_SOFT_RIGHT
static int SYM
          KeyEvent.KEYCODE_SYM
static int TAB
          KeyEvent.KEYCODE_TAB
static int UP
          KeyEvent.KEYCODE_DPAD_UP
static int VOLUME_DOWN
          KeyEvent.KEYCODE_VOLUME_UP
static int VOLUME_UP
          KeyEvent.KEYCODE_VOLUME_DOWN
 
Constructor Summary
TestCase()
           
TestCase(String name)
           
 
Method Summary
protected  List<Activity> activities()
          Get all the unfinished activities in the target package, most recent first.
protected  Activity activity()
          Get the most recent unfinished activity in the target package.
protected  void addMonitor(Instrumentation.ActivityMonitor monitor)
           
protected  Instrumentation.ActivityMonitor addMonitor(IntentFilter filter, Instrumentation.ActivityResult result, boolean block)
           
protected  Instrumentation.ActivityMonitor addMonitor(String cls, Instrumentation.ActivityResult result, boolean block)
           
protected
<T> T
at(Class<T> asA, Object from, String path)
           
protected
<T> T
at(Class<T> asA, String path)
           
protected  Object at(String path)
           
protected  void backup()
           
protected  void backup(String database)
           
protected  boolean booleanAt(String path)
           
protected  void callActivityOnCompleteThaw(Activity activity, Bundle icicle)
           
protected  void callActivityOnCreate(Activity activity, Bundle icicle)
           
protected  void callActivityOnFreeze(Activity activity, Bundle outState)
           
protected  void callActivityOnNewIntent(Activity activity, Intent intent)
           
protected  void callActivityOnPause(Activity activity)
           
protected  void callActivityOnPostCreate(Activity activity, Bundle icicle)
           
protected  void callActivityOnRestart(Activity activity)
           
protected  void callActivityOnResume(Activity activity)
           
protected  void callActivityOnStart(Activity activity)
           
protected  void callApplicationOnCreate(Application app)
           
protected  boolean checkMonitorHit(Instrumentation.ActivityMonitor monitor, int minHits)
           
protected  void click()
          sendKeyDownUp(KEYCODE_DPAD_CENTER)
protected  double doubleAt(String path)
           
protected  Bitmap dupWindowBitmap(Activity activity)
          dupWindowBitmapSync, resuming momentarily if necessary.
protected  Bitmap dupWindowBitmapSync(Activity activity)
           
protected  void execSql(String database, int... scriptsAsRawResources)
           
protected  Instrumentation.ActivityResult execStartActivity(ApplicationContext who, IBinder token, Activity target, Intent intent, int requestCode)
           
protected  void finish()
          finish(activity()), resuming momentarily as needed.
protected  void finish(Activity activity)
          Finish the given activity by calling finish() on the main thread.
protected  void finish(int resultCode, Bundle results)
           
protected  void finishAll()
          finish() all unfinished activities; useful in tearDown().
protected  void getAllocCounts(Bundle results)
           
protected  Context getContext()
           
protected  Context getTargetContext()
           
protected  int intAt(String path)
           
protected  void invokeMenuAction(Activity targetActivity, int id, int flag)
          invokeMenuActionSync, resuming momentarily if necessary.
protected  void invokeMenuActionSync(Activity targetActivity, int id, int flag)
           
protected  boolean isProfiling()
           
protected  Activity newActivity(ClassLoader cl, String className, Intent intent)
           
protected  Application newApplication(ClassLoader cl, String className)
           
protected  void onCreate(Bundle arguments)
           
protected  void onDestroy()
           
protected  boolean onException(Object obj, Throwable e)
           
protected  void onStart()
           
protected  void pause()
          Pause execution of the target package.
protected  boolean paused()
          Is the target package paused?
protected  void pauseNow()
          Like pause, but do not implicitly call waitForIdleSync().
protected  void press(Object... keys)
          sendKeyDownUpSync on all keys in order, resuming momentarily if necessary.
protected  void removeMonitor(Instrumentation.ActivityMonitor monitor)
           
protected  void restore()
           
protected  void restore(String database)
           
protected  void resume()
          Resume executing the target package if it has been paused.
protected  void runOnMainSync(Runnable runner)
           
protected  void sendCharacter(int keyCode)
          sendCharacterSync, resuming momentarily if necessary.
protected  void sendCharacterSync(int keyCode)
           
protected  void sendKey(KeyEvent event)
          sendKeySync, resuming momentarily if necessary.
protected  void sendKeyDownUp(int key)
          sendKeyDownUpSync, resuming momentarily if necessary.
protected  void sendKeyDownUpSync(int key)
           
protected  void sendKeySync(KeyEvent event)
           
protected  void sendString(String text)
          sendStringSync, resuming momentarily if necessary.
protected  void sendStringSync(String text)
           
 void setInstrumentation(Positron positron)
           
protected  void start()
           
protected  Activity startActivity(Intent intent)
          startActivitySync, resuming momentarily if necessary.
protected  Activity startActivitySync(Intent intent)
           
protected  Activity startActivitySync(String className)
          Shortcut to startActivitySync the named class in the target context.
protected  void startAllocCounting()
           
protected  void startProfiling()
           
protected  void stopAllocCounting()
           
protected  void stopProfiling()
           
protected  String stringAt(String path)
           
protected  void tearDown()
          finishAll();
protected  View viewAt(String path)
           
protected  void waitForIdle()
          waitForIdleSync, resuming momentarily if necessary.
protected  void waitForIdle(Runnable recipient)
           
protected  void waitForIdleSync()
           
protected  Activity waitForMonitor(Instrumentation.ActivityMonitor monitor)
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLICK

public static final int CLICK
KeyEvent.KEYCODE_DPAD_CENTER

See Also:
Constant Field Values

CENTER

public static final int CENTER
KeyEvent.KEYCODE_DPAD_CENTER

See Also:
Constant Field Values

UP

public static final int UP
KeyEvent.KEYCODE_DPAD_UP

See Also:
Constant Field Values

DOWN

public static final int DOWN
KeyEvent.KEYCODE_DPAD_DOWN

See Also:
Constant Field Values

LEFT

public static final int LEFT
KeyEvent.KEYCODE_DPAD_LEFT

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
KeyEvent.KEYCODE_DPAD_RIGHT

See Also:
Constant Field Values

BACK

public static final int BACK
KeyEvent.KEYCODE_BACK

See Also:
Constant Field Values

CALL

public static final int CALL
KeyEvent.KEYCODE_CALL

See Also:
Constant Field Values

CAMERA

public static final int CAMERA
KeyEvent.KEYCODE_CAMERA

See Also:
Constant Field Values

CAP

public static final int CAP
KeyEvent.KEYCODE_CAP

See Also:
Constant Field Values

CLEAR

public static final int CLEAR
KeyEvent.KEYCODE_CLEAR

See Also:
Constant Field Values

ENDCALL

public static final int ENDCALL
KeyEvent.KEYCODE_ENDCALL

See Also:
Constant Field Values

ENVELOPE

public static final int ENVELOPE
KeyEvent.KEYCODE_ENVELOPE

See Also:
Constant Field Values

EXPLORER

public static final int EXPLORER
KeyEvent.KEYCODE_EXPLORER

See Also:
Constant Field Values

ALT

public static final int ALT
KeyEvent.KEYCODE_ALT


HOME

public static final int HOME
KeyEvent.KEYCODE_HOME

See Also:
Constant Field Values

NEWLINE

public static final int NEWLINE
KeyEvent.KEYCODE_NEWLINE

See Also:
Constant Field Values

NUM

public static final int NUM
KeyEvent.KEYCODE_NUM

See Also:
Constant Field Values

POWER

public static final int POWER
KeyEvent.KEYCODE_POWER

See Also:
Constant Field Values

SOFT_LEFT

public static final int SOFT_LEFT
KeyEvent.KEYCODE_SOFT_LEFT

See Also:
Constant Field Values

SOFT_RIGHT

public static final int SOFT_RIGHT
KeyEvent.KEYCODE_SOFT_RIGHT

See Also:
Constant Field Values

SYM

public static final int SYM
KeyEvent.KEYCODE_SYM

See Also:
Constant Field Values

TAB

public static final int TAB
KeyEvent.KEYCODE_TAB

See Also:
Constant Field Values

VOLUME_UP

public static final int VOLUME_UP
KeyEvent.KEYCODE_VOLUME_DOWN

See Also:
Constant Field Values

VOLUME_DOWN

public static final int VOLUME_DOWN
KeyEvent.KEYCODE_VOLUME_UP

See Also:
Constant Field Values
Constructor Detail

TestCase

public TestCase(String name)

TestCase

public TestCase()
Method Detail

setInstrumentation

public void setInstrumentation(Positron positron)

tearDown

protected void tearDown()
                 throws Exception
finishAll();

Overrides:
tearDown in class TestCase
Throws:
Exception

activity

protected Activity activity()
Get the most recent unfinished activity in the target package. This isn't quite correct. The instrumentation can only detect new activities in the target package that list the package as a category. So, if the tested package is "my.android.app", then each activity declared in it's AndroidManifest.xml needs a tag within it's intent-filter. Also remember, under all circumstances the instrumentation can only detect activities declared in the target package, according to the targetPackage attribute of the tag positron was declared with. Other started activities, such as contacts or the system browser, will have to be mocked out instead. See the Instrumentation.ActivityMonitor documentation on how to do that.


activities

protected List<Activity> activities()
Get all the unfinished activities in the target package, most recent first. The same restrictions described in activity() apply here. The list is unmodifiable.


finish

protected void finish(Activity activity)
Finish the given activity by calling finish() on the main thread. This method will resume momentarily if needed.


finish

protected void finish()
finish(activity()), resuming momentarily as needed.


finishAll

protected void finishAll()
finish() all unfinished activities; useful in tearDown(). This method will resume if needed but not immediately pause again.


pause

protected void pause()
Pause execution of the target package. This is useful for inspecting the view state of the target package, since doing so while it is running can create race conditions. Resume execution with resume(). Pausing an already-paused application is a safe no-op. Paused applications can't respond to events, nor execute synchronous commands such as sendStringSync (or any *Sync.) Keep this in mind when writing tests. This version calls waitForIdleSync before pauing. To skip waitForIdleSync, try pauseNow(). Pausing is done by asynchronously calling Instrumentation.runOnMainSync on a blocking operation.


pauseNow

protected void pauseNow()
Like pause, but do not implicitly call waitForIdleSync().


resume

protected void resume()
Resume executing the target package if it has been paused. Resuming an unpaused package is a safe noop.


paused

protected boolean paused()
Is the target package paused?


startActivitySync

protected Activity startActivitySync(String className)
Shortcut to startActivitySync the named class in the target context.

Parameters:
className - fully-qualified class name of the action to start.

dupWindowBitmap

protected Bitmap dupWindowBitmap(Activity activity)
dupWindowBitmapSync, resuming momentarily if necessary.


invokeMenuAction

protected void invokeMenuAction(Activity targetActivity,
                                int id,
                                int flag)
invokeMenuActionSync, resuming momentarily if necessary.


sendCharacter

protected void sendCharacter(int keyCode)
sendCharacterSync, resuming momentarily if necessary.


sendKey

protected void sendKey(KeyEvent event)
sendKeySync, resuming momentarily if necessary.


sendKeyDownUp

protected void sendKeyDownUp(int key)
sendKeyDownUpSync, resuming momentarily if necessary.


click

protected void click()
sendKeyDownUp(KEYCODE_DPAD_CENTER)


press

protected void press(Object... keys)
sendKeyDownUpSync on all keys in order, resuming momentarily if necessary. Combined with the renamed constants available in positron.TestCase, this enables things like press(UP, UP, DOWN, DOWN, LEFT, RIGHT, LEFT, RIGHT, "ba") which may otherwise be cumbersome.

Parameters:
keys - A mixture of ints and Strings. ints are sent with sendKeyDownUpSync, Strings are send with sendStringSync.
Throws:
IllegalArgumentException - if something other than an int or String was passed.

at

protected <T> T at(Class<T> asA,
                   Object from,
                   String path)

at

protected <T> T at(Class<T> asA,
                   String path)

at

protected Object at(String path)

viewAt

protected View viewAt(String path)

booleanAt

protected boolean booleanAt(String path)

doubleAt

protected double doubleAt(String path)

intAt

protected int intAt(String path)

stringAt

protected String stringAt(String path)

sendString

protected void sendString(String text)
sendStringSync, resuming momentarily if necessary.


startActivity

protected Activity startActivity(Intent intent)
startActivitySync, resuming momentarily if necessary.


waitForIdle

protected void waitForIdle()
waitForIdleSync, resuming momentarily if necessary.


addMonitor

protected void addMonitor(Instrumentation.ActivityMonitor monitor)

addMonitor

protected Instrumentation.ActivityMonitor addMonitor(IntentFilter filter,
                                                     Instrumentation.ActivityResult result,
                                                     boolean block)

addMonitor

protected Instrumentation.ActivityMonitor addMonitor(String cls,
                                                     Instrumentation.ActivityResult result,
                                                     boolean block)

callActivityOnCompleteThaw

protected void callActivityOnCompleteThaw(Activity activity,
                                          Bundle icicle)

callActivityOnCreate

protected void callActivityOnCreate(Activity activity,
                                    Bundle icicle)

callActivityOnFreeze

protected void callActivityOnFreeze(Activity activity,
                                    Bundle outState)

callActivityOnNewIntent

protected void callActivityOnNewIntent(Activity activity,
                                       Intent intent)

callActivityOnPause

protected void callActivityOnPause(Activity activity)

callActivityOnPostCreate

protected void callActivityOnPostCreate(Activity activity,
                                        Bundle icicle)

callActivityOnRestart

protected void callActivityOnRestart(Activity activity)

callActivityOnResume

protected void callActivityOnResume(Activity activity)

callActivityOnStart

protected void callActivityOnStart(Activity activity)

callApplicationOnCreate

protected void callApplicationOnCreate(Application app)

checkMonitorHit

protected boolean checkMonitorHit(Instrumentation.ActivityMonitor monitor,
                                  int minHits)

dupWindowBitmapSync

protected Bitmap dupWindowBitmapSync(Activity activity)

execStartActivity

protected Instrumentation.ActivityResult execStartActivity(ApplicationContext who,
                                                           IBinder token,
                                                           Activity target,
                                                           Intent intent,
                                                           int requestCode)

finish

protected void finish(int resultCode,
                      Bundle results)

getAllocCounts

protected void getAllocCounts(Bundle results)

getContext

protected Context getContext()

getTargetContext

protected Context getTargetContext()

invokeMenuActionSync

protected void invokeMenuActionSync(Activity targetActivity,
                                    int id,
                                    int flag)

isProfiling

protected boolean isProfiling()

newActivity

protected Activity newActivity(ClassLoader cl,
                               String className,
                               Intent intent)
                        throws InstantiationException,
                               IllegalAccessException,
                               ClassNotFoundException
Throws:
InstantiationException
IllegalAccessException
ClassNotFoundException

newApplication

protected Application newApplication(ClassLoader cl,
                                     String className)
                              throws InstantiationException,
                                     IllegalAccessException,
                                     ClassNotFoundException
Throws:
InstantiationException
IllegalAccessException
ClassNotFoundException

onCreate

protected void onCreate(Bundle arguments)

onDestroy

protected void onDestroy()

onException

protected boolean onException(Object obj,
                              Throwable e)

onStart

protected void onStart()

removeMonitor

protected void removeMonitor(Instrumentation.ActivityMonitor monitor)

runOnMainSync

protected void runOnMainSync(Runnable runner)

sendCharacterSync

protected void sendCharacterSync(int keyCode)

sendKeyDownUpSync

protected void sendKeyDownUpSync(int key)

sendKeySync

protected void sendKeySync(KeyEvent event)

sendStringSync

protected void sendStringSync(String text)

start

protected void start()

startActivitySync

protected Activity startActivitySync(Intent intent)

startAllocCounting

protected void startAllocCounting()

startProfiling

protected void startProfiling()

stopAllocCounting

protected void stopAllocCounting()

stopProfiling

protected void stopProfiling()

waitForIdle

protected void waitForIdle(Runnable recipient)

waitForIdleSync

protected void waitForIdleSync()

waitForMonitor

protected Activity waitForMonitor(Instrumentation.ActivityMonitor monitor)

backup

protected void backup()

backup

protected void backup(String database)

execSql

protected void execSql(String database,
                       int... scriptsAsRawResources)

restore

protected void restore()

restore

protected void restore(String database)