I am testing an app by sending mock intents to an Android activity via
the Android instrumentation tools and Android JUnit in Eclipse.

I am able to successfully create a test that sends one Intent to an
Activity, but I want to automate this and send several consecutive
Intents so I can test the Activity with many pieces of data put in as
an "extra" in the Intent. My code (which works for a single Intent) is
as follows:

public class SearchTest extends
ActivityInstrumentationTestCase2<SearchResults> {

    private ListActivity mActivity;
    private ArrayList<String> testManifest = new ArrayList<String>();
    TextView tv;


    public SearchTest() {
        super("org.fdroid.fdroid", SearchResults.class);
    }//SearchTest

    @Override
    protected void setUp() throws Exception{
        setUpTestManifest();
        super.setUp();
        setActivityInitialTouchMode(false);
        Intent i = new Intent(Intent.ACTION_SEARCH);
        i.setClassName("org.fdroid.fdroid",
"org.fdroid.fdroid.SearchResults");
        i.putExtra(SearchManager.QUERY, testManifest.get(0));
        setActivityIntent(i);
        mActivity = getActivity();
        tv = (TextView) mActivity.findViewById(R.id.description);
    }//setUp

    public void testSearchResult(){
        assertTrue(mActivity.getListView().getCount() > 0);
    }//testSearchResult

    public void setUpTestManifest(){
        //populate the test manifest
        testManifest.add("Sample Key Word 1");
        testManifest.add("Sample Key Word 2");
        testManifest.add("Sample Key Word 3");
    }//setupManifest

}//SearchTest

How can I make this work where I can have hundreds of items in the
testManifest and create an Intent and test for each of those items?

Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to