FileDocCategorySizeDatePackage
TestBrowserActivity.javaAPI DocAndroid 1.5 API4606Wed May 06 22:42:02 BST 2009android.test

TestBrowserActivity

public abstract class TestBrowserActivity extends android.app.ListActivity implements TestSuiteProvider, android.test.TestBrowserView, AdapterView.OnItemClickListener
hide
- This is part of a framework that is under development and should not be used for active development.

Fields Summary
private TestBrowserController
mTestBrowserController
public static final String
BUNDLE_EXTRA_PACKAGE
Constructors Summary
Methods Summary
public junit.framework.TestSuitegetTestSuite()

        return getTopTestSuite();
    
private junit.framework.TestSuitegetTestSuiteToBrowse()
Subclasses will override this method and return the TestSuite specific to their .apk. When this method is invoked due to an intent fired from {@link #onItemClick(android.widget.AdapterView, android.view.View, int, long)} then get the targeted TestSuite from the intent.

return
testSuite to browse

        Intent intent = getIntent();
        if (Intent.ACTION_RUN.equals(intent.getAction())) {
            String testClassName = intent.getData().toString();

            try {
                Class<Test> testClass = (Class<Test>) getClassLoader().loadClass(testClassName);
                return TestCaseUtil.createTestSuite(testClass);
            } catch (ClassNotFoundException e) {
                Log.e("TestBrowserActivity", "ClassNotFoundException for " + testClassName, e);
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                Log.e("TestBrowserActivity", "IllegalAccessException for " + testClassName, e);
                throw new RuntimeException(e);
            } catch (InstantiationException e) {
                Log.e("TestBrowserActivity", "InstantiationException for " + testClassName, e);
                throw new RuntimeException(e);
            }
        } else {
            // get test classes to browwes from subclass
            return getTopTestSuite();
        }

    
public abstract junit.framework.TestSuitegetTopTestSuite()

return
A TestSuite that should be run for a given application.

protected voidonCreate(android.os.Bundle savedInstanceState)


    
        
        super.onCreate(savedInstanceState);

        getListView().setOnItemClickListener(this);

        mTestBrowserController = ServiceLocator.getTestBrowserController();
        mTestBrowserController.setTargetPackageName(getPackageName());
        mTestBrowserController.registerView(this);
        mTestBrowserController.setTargetBrowserActivityClassName(this.getClass().getName());

        // Apk paths used to search for test classes when using TestSuiteBuilders.
        String[] apkPaths = {getPackageCodePath()};
        ClassPathPackageInfoSource.setApkPaths(apkPaths);
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View v, int position, long id)

        Intent intent = mTestBrowserController.getIntentForTestAt(position);
        intent.putExtra(BUNDLE_EXTRA_PACKAGE, getPackageName());
        startActivity(intent);
    
protected voidonStart()

        super.onStart();
        TestSuite testSuite = getTestSuiteToBrowse();
        mTestBrowserController.setTestSuite(testSuite);
        
        String name = testSuite.getName();
        if (name != null) {
            setTitle(name.substring(name.lastIndexOf(".") + 1));
        }
    
public voidsetTestNames(java.util.List testNames)

        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
                R.layout.test_list_item, testNames);
        setListAdapter(arrayAdapter);