Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to test a ListActivity?
    primarykey
    data
    text
    <p>I'm new to Android development as well as test-driven development. I want to write unit tests for the following ListActivity:</p> <pre><code>public class TrendsMainActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] list_items = getResources().getStringArray(R.array.trend_menu_names); setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.main, list_items)); } @Override protected void onListItemClick(ListView listView, View view, int position, long id) { Intent intent = null; switch(position) { case 0: intent = new Intent(this, TrendingActivity.class); break; case 1: intent = new Intent(this, SearchActivity.class); break; case 2: intent = new Intent(this, TimelineActivity.class); break; } if(intent != null) { startActivity(intent); } else { Log.e(getClass().getSimpleName(), "There was an error retrieving request."); } }} </code></pre> <p>I have scoured all of the documentation that I can find, but I can not figure out how to test this Activity. The onListItemClick method is not finished, but it gives the idea of what I want to accomplish. I want to test clicking the first item in the ListView, and test that the correct Activity is being started. </p> <p>How can I accomplish this?</p> <p>Edit: I want my test to "click" on an item in the ListView. I then want to assert that the activity started is the correct activity (e.g. Clicking ListView item 0 starts the TrendingActivity specifically)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload