FileDocCategorySizeDatePackage
AndroidTestCase.javaAPI DocAndroid 1.5 API2727Wed May 06 22:41:56 BST 2009android.test

AndroidTestCase

public class AndroidTestCase extends TestCase
Extend this if you need to access Resources or other things that depend on Activity Context.

Fields Summary
protected android.content.Context
mContext
Constructors Summary
Methods Summary
public android.content.ContextgetContext()

        return mContext;
    
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!");
                }
            }
        }
    
public voidsetContext(android.content.Context context)

        mContext = context;
    
protected voidsetUp()

        super.setUp();
    
protected voidtearDown()

        super.tearDown();
    
public voidtestAndroidTestCaseSetupProperly()

        assertNotNull("Context is null. setContext should be called before tests are run",
                mContext);