Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4560638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:57:34+00:00 2026-05-21T17:57:34+00:00

I am trying to send mock intents to an Android activity via the Android

  • 0

I am trying to send 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:57:34+00:00Added an answer on May 21, 2026 at 5:57 pm

    Have you tried pulling out the launching of the activity out of the setUp code and into a loop within your test method? Example,

    protected void setUp() {
        setUpTestManifest();
        super.setUp();
    } 
    
    public void testSearchResult(){
        for (String query : testManifest) {
            setActivityInitialTouchMode(false);
            Intent i = new Intent(Intent.ACTION_SEARCH);
            i.setClassName("org.fdroid.fdroid", "org.fdroid.fdroid.SearchResults");
            i.putExtra(SearchManager.QUERY, query);
            setActivityIntent(i);
            mActivity = getActivity();
            tv = (TextView) mActivity.findViewById(R.id.description);
            assertTrue(mActivity.getListView().getCount() > 0);
            mActivity.finish();  // close the activity
            setActivity(null);   // forces next call of getActivity to re-open the activity
        }
    }
    

    -Dan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to test an Android application. I need to send mock location
Am trying to send out a multicast pakcet via usb interface of android.The code
While trying to send a POST request via xmlhttp.open(POST, url, true) (javascript) to the
Im trying to send a List to next activity the list List mGF =
Im trying to send a Docx file via this form that I made, the
Im trying to send multiple data items over a tcp socket from an android
I am trying to send email via System.Net.Mail. On clicking send I am getting
Trying to send a html email via mail(), however gmail just displays the email
im trying to send a picture from a android device to a server and
i`m trying to send an email using native email client on android phone. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.