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 8954139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:15:02+00:00 2026-06-15T14:15:02+00:00

I have extensive use of ArrayAdapter in my app because most Activities are holding

  • 0

I have extensive use of ArrayAdapter in my app because most Activities are holding a ListView and I need some custom stuff in them.

I took a look at the test classes in the android developer documentation but wasn’t able to find some examples or a proper testclass…

1) Are there any best practices for (unit)-testing ArrayAdapter in Android?

2) May I have chosen the wrong approach (with the adapters) and killed testability this way?

  • 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-06-15T14:15:03+00:00Added an answer on June 15, 2026 at 2:15 pm

    You can write the test extending AndroidTestCase It will looks something like this:

    public class ContactsAdapterTest extends AndroidTestCase {
        private ContactsAdapter mAdapter;
    
        private Contact mJohn;
        private Contact mJane;
    
        public ContactsAdapterTest() {
            super();
        }
    
        protected void setUp() throws Exception {
            super.setUp();
            ArrayList<Contact> data = new ArrayList<Contact>();
    
            mJohn = new Contact("John", "+34123456789", "uri");
            mJane = new Contact("Jane", "+34111222333", "uri");
            data.add(mJohn);
            data.add(mJane);
            mAdapter = new ContactsAdapter(getContext(), data);
        }
    
    
        public void testGetItem() {
            assertEquals("John was expected.", mJohn.getName(),
                    ((Contact) mAdapter.getItem(0)).getName());
        }
    
        public void testGetItemId() {
            assertEquals("Wrong ID.", 0, mAdapter.getItemId(0));
        }
    
        public void testGetCount() {
            assertEquals("Contacts amount incorrect.", 2, mAdapter.getCount());
        }
    
        // I have 3 views on my adapter, name, number and photo
        public void testGetView() {
            View view = mAdapter.getView(0, null, null);
    
            TextView name = (TextView) view
                    .findViewById(R.id.text_contact_name);
    
            TextView number = (TextView) view
                    .findViewById(R.id.text_contact_number);
    
            ImageView photo = (ImageView) view
                    .findViewById(R.id.image_contact_photo);
    
            //On this part you will have to test it with your own views/data
            assertNotNull("View is null. ", view);
            assertNotNull("Name TextView is null. ", name);
            assertNotNull("Number TextView is null. ", number);
            assertNotNull("Photo ImageView is null. ", photo);
    
            assertEquals("Names doesn't match.", mJohn.getName(), name.getText());
            assertEquals("Numbers doesn't match.", mJohn.getNumber(),
                    number.getText());
        }
    }
    

    Probably you will have to test getView several times with different arguments, to test all scenarios.

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

Sidebar

Related Questions

I have a codeigniter app that makes extensive use of sessions, specifically using database
I have an app that makes extensive use of a WebView. When the user
I have a webforms page that makes quite extensive use of AJAX. There are
We have inherited an application (Java-based, running on WebLogic 10.3.5) that makes extensive use
We have a MediaWiki wiki in which we make extensive use of templates. These
I have an ASP.NET application that makes extensive use of ASP.NET cache API for
I've developed a Webbapp that makes an extensive use of threads. We need to
We use EventBrite for managing some free events: works great. We also make extensive
I have a multi-threaded Win32 service written in C++ (VS2010) that makes extensive use
I have a .NET MVC application which makes extensive use of AJAX and modal

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.