FileDocCategorySizeDatePackage
ActivityTestCase.javaAPI DocAndroid 1.5 API2738Wed May 06 22:42:02 BST 2009android.test

ActivityTestCase

public abstract class ActivityTestCase extends InstrumentationTestCase
This is common code used to support Activity test cases. For more useful classes, please see {@link android.test.ActivityUnitTestCase} and {@link android.test.ActivityInstrumentationTestCase}.

Fields Summary
private android.app.Activity
mActivity
The activity that will be set up for use in each test method.
Constructors Summary
Methods Summary
protected android.app.ActivitygetActivity()

return
Returns the activity under test.

        return mActivity;
    
protected voidscrubClass(java.lang.Class testCaseClass)
This function is called by various TestCase implementations, at tearDown() time, in order to scrub out any class variables. This protects against memory leaks in the case where a test case creates a non-static inner class (thus referencing the test case) and gives it to someone else to hold onto.

param
testCaseClass The class of the derived TestCase implementation.
throws
IllegalAccessException

        final Field[] fields = getClass().getDeclaredFields();
        for (Field field : fields) {
            final Class<?> fieldClass = field.getDeclaringClass();
            if (testCaseClass.isAssignableFrom(fieldClass) && !field.getType().isPrimitive()) {
                try {
                    field.setAccessible(true);
                    field.set(this, null);
                } catch (Exception e) {
                    android.util.Log.d("TestCase", "Error: Could not nullify field!");
                }

                if (field.get(this) != null) {
                    android.util.Log.d("TestCase", "Error: Could not nullify field!");
                }
            }
        }
    
protected voidsetActivity(android.app.Activity testActivity)
Set the activity under test.

param
testActivity The activity under test

        mActivity = testActivity;