FileDocCategorySizeDatePackage
SingleLaunchActivityTestCase.javaAPI DocAndroid 5.1 API2970Thu Mar 12 22:22:42 GMT 2015android.test

SingleLaunchActivityTestCase

public abstract class SingleLaunchActivityTestCase extends InstrumentationTestCase
If you would like to test a single activity with an {@link android.test.InstrumentationTestCase}, this provides some of the boiler plate to launch and finish the activity in {@link #setUp} and {@link #tearDown}. This launches the activity only once for the entire class instead of doing it in every setup / teardown call.

Fields Summary
String
mPackage
Class
mActivityClass
private static int
sTestCaseCounter
private static boolean
sActivityLaunchedFlag
private static android.app.Activity
sActivity
The activity that will be set up for use in each test method.
Constructors Summary
public SingleLaunchActivityTestCase(String pkg, Class activityClass)
NOTE: The parameter pkg must refer to the package identifier of the package hosting the activity to be launched, which is specified in the AndroidManifest.xml file. This is not necessarily the same as the java package name.

param
pkg The package hosting the activity to be launched.
param
activityClass The activity to test.


                                                               
         
        mPackage = pkg;
        mActivityClass = activityClass;        
        sTestCaseCounter ++;                
    
Methods Summary
public TgetActivity()

        return (T) sActivity;
    
protected voidsetUp()

        super.setUp();
        // If it is the first test case, launch the activity.
        if (!sActivityLaunchedFlag) {
            // by default, not in touch mode
            getInstrumentation().setInTouchMode(false);
            sActivity = launchActivity(mPackage, mActivityClass, null);
            sActivityLaunchedFlag = true;
        }                        
    
protected voidtearDown()

        // If it is the last test case, call finish on the activity.
        sTestCaseCounter --;
        if (sTestCaseCounter == 0) {
            sActivity.finish();
        }        
        super.tearDown();
    
public voidtestActivityTestCaseSetUpProperly()

        assertNotNull("activity should be launched successfully", sActivity);