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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:39:01+00:00 2026-05-23T17:39:01+00:00

I am trying to test my activity using either ActivityUnitTestCase or ActivityInstrumentationTestCase2. In the

  • 0

I am trying to test my activity using either ActivityUnitTestCase or ActivityInstrumentationTestCase2. In the activity I want to test my

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        menu.setHeaderTitle(R.string.lcMenuHeader);

        menu.add(Menu.NONE, EDIT_MENU_POS, EDIT_MENU_POS, R.string.lcEditAccount);
        menu.add(Menu.NONE, COPY_MENU_POS, COPY_MENU_POS, R.string.lcCopyAccount);
        menu.add(Menu.NONE, DELETE_MENU_POS, DELETE_MENU_POS, R.string.lcDeleteAccount);
}

How can I test that the menu is in the right state – ie. 3 items and a given header? I can trigger it being created in my ActivityInstrumentationTestCase2 test using

textView.performLongClick();

But I don’t know how to get it back.

Thanks
Stephen

  • 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-23T17:39:01+00:00Added an answer on May 23, 2026 at 5:39 pm

    In the end, I used reflection with the ActivityUnitTestCase test case:

    AccountEntryContextMenuMock mock = new AccountEntryContextMenuMock();
    ContextMenu menu = (ContextMenu)Proxy.newProxyInstance(mLogInActivity.
        getClassLoader(), new Class<?>[] { ContextMenu.class }, mock);
    
    mLogInActivity.onCreateContextMenu(menu, accList, null);
    //Now query the mock that the right things happened
    

    With the mock menu looking like:

    public class AccountEntryContextMenuMock implements InvocationHandler {
    
        @Override
        public Object invoke(Object proxy, Method method, Object[] args)
                throws Throwable {
    
            if (method.getName().equals("setHeaderTitle")) {
                 //record it and make available for test
            }
            else if (method.getName().equals("add")) {
                 //record it and make available for test
            }
    
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to test an Activity in android which will show a ProgressDialog and
Im trying to test my successfully creates a new user after login (using authlogic).
I am trying to test drive an application feature using Robotium. One of the
I'm trying to parse some html using jsoup (1.3.3) in my android activity. When
Here is the test code that I am using : public class IOConnectDirect extends
I'm trying to decrypt an encrypted image in Android using this code: public class
I'm trying to test a simple SQLite database using Robolectric in my Android application.
just trying to test for equality in this piece of code, but getting a
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
I'm trying to test the DB2 adapter for BizTalk 2006 (not R2). While trying

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.