FileDocCategorySizeDatePackage
TestListActivity.javaAPI DocAndroid 1.5 API8115Wed May 06 22:42:02 BST 2009android.test

TestListActivity

public abstract class TestListActivity extends android.app.ListActivity
Activity base class to use to implement your application's tests.

Implement the getTestSuite() method to return the name of your test suite class.

See the android.test package documentation (click the more... link) for a full description {@hide} Not needed for SDK

Fields Summary
public static final String
PERFORMANCE_TESTS
Supplied in the intent extras if we are running performance tests.
static final int
MODE_GROUP
"Mode" group in the menu.
String
mSuite
Our suite
String[]
mTests
Our children tests
private int
mMode
which mode, REGRESSION, PERFORMANCE or PROFILING
private android.view.MenuItem
mRegressionItem
"Regression" menu item
private android.view.MenuItem
mPerformanceItem
"Performance" menu item
private android.view.MenuItem
mProfilingItem
"Profiling" menu item
private final Comparator
sComparator
Constructors Summary
public TestListActivity()
Constructor that doesn't do much.


              
      
        super();
    
Methods Summary
private voidaddTestRows(android.database.MatrixCursor cursor)

        int id = 0;
        cursor.newRow().add("Run All").add(id++);       
        for (String test : mTests) {
            String title = TestRunner.getTitle(test);
            String prefix = TestRunner.isTestSuite(this, test)
                    ? "Browse " : "Run ";

            // I'd rather do this with an icon column, but I don't know how
            cursor.newRow().add(prefix + title).add(id++);
        }
    
public abstract java.lang.StringgetTestSuite()
Subclasses should implement this to return the names of the classes of their tests.

return
test suite class name

private java.lang.StringmakeCompareName(java.lang.String s)

        int index = s.lastIndexOf('.");
        
        if (index == -1) {
            return s;
        }
        
        return s.substring(index + 1);
    
public voidonCreate(android.os.Bundle icicle)
Typical onCreate(Bundle icicle) implementation.

        super.onCreate(icicle);

        Intent intent = getIntent();

        mMode = intent.getIntExtra(TestListActivity.PERFORMANCE_TESTS, mMode);


        if (intent.getAction().equals(Intent.ACTION_MAIN)) {
            // if we were called as MAIN, get the test suites,
            mSuite = getTestSuite();
        } else if (intent.getAction().equals(Intent.ACTION_RUN)) {
            // We should have been provided a status channel.  Bail out and
            // run the test instead.  This is how the TestHarness gets us
            // loaded in our process for "Run All Tests."
            Intent ntent = new Intent(Intent.ACTION_RUN,
                    intent.getData() != null
                            ? intent.getData()
                            : Uri.parse(getTestSuite()));
            ntent.setClassName("com.android.testharness",
                    "com.android.testharness.RunTest");
            ntent.putExtras(intent);
            ntent.putExtra("package", getPackageName());
            startActivity(ntent);
            finish();
            return;
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // otherwise use the one in the intent
            mSuite = intent.getData() != null ? intent.getData().toString()
                    : null;
        }

        String[] children = TestRunner.getChildren(this, mSuite);

        Arrays.sort(children, sComparator);

        int len = children.length;
        mTests = new String[len];
        System.arraycopy(children, 0, mTests, 0, len);

        setTitle(TestRunner.getTitle(mSuite));

        MatrixCursor cursor = new MatrixCursor(new String[] { "name", "_id" });
        addTestRows(cursor);

        CursorAdapter adapter = new SimpleCursorAdapter(
                this,
                com.android.internal.R.layout.simple_list_item_1,
                cursor,
                new String[] {"name"},
                new int[] {com.android.internal.R.id.text1});
        
        setListAdapter(adapter);
    
public booleanonCreateOptionsMenu(android.view.Menu menu)

        super.onCreateOptionsMenu(menu);
        mRegressionItem = menu.add(MODE_GROUP, -1, 0, "Regression Mode");
        mPerformanceItem = menu.add(MODE_GROUP, -1, 0, "Performance Mode");
        mProfilingItem = menu.add(MODE_GROUP, -1, 0, "Profiling Mode");
        menu.setGroupCheckable(MODE_GROUP, true, true);
        return true;
    
protected voidonListItemClick(android.widget.ListView l, android.view.View v, int position, long id)

        Intent intent = new Intent();

        if (position == 0) {
            if (false) {
                intent.setClassName("com.android.testharness",
                        "com.android.testharness.RunAll");
                intent.putExtra("tests", new String[]{mSuite});
            } else {
                intent.setClassName("com.android.testharness",
                        "com.android.testharness.RunTest");
                intent.setAction(Intent.ACTION_RUN);
                intent.setData(Uri.parse(mSuite));
            }
        } else {
            String test = mTests[position - 1];
            if (TestRunner.isTestSuite(this, test)) {
                intent.setClassName(getPackageName(), this.getClass().getName());
                intent.setAction(Intent.ACTION_VIEW);
            } else {
                intent.setClassName("com.android.testharness",
                        "com.android.testharness.RunTest");
            }
            intent.setData(Uri.parse(test));
        }

        intent.putExtra(PERFORMANCE_TESTS, mMode);
        intent.putExtra("package", getPackageName());
        startActivity(intent);
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        if (item == mRegressionItem) {
            mMode = TestRunner.REGRESSION;
        } else if (item == mPerformanceItem) {
            mMode = TestRunner.PERFORMANCE;
        } else if (item == mProfilingItem) {
            mMode = TestRunner.PROFILING;
        }
        
        return true;
    
public booleanonPrepareOptionsMenu(android.view.Menu menu)

        super.onPrepareOptionsMenu(menu);
        switch (mMode) {
        case TestRunner.REGRESSION:
            mRegressionItem.setChecked(true);
            break;

        case TestRunner.PERFORMANCE:
            mPerformanceItem.setChecked(true);
            break;

        case TestRunner.PROFILING:
            mProfilingItem.setChecked(true);
            break;
        }
        return true;
    
protected voidonResume()

        super.onResume();