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

  • Home
  • SEARCH
  • 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 8831105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:14:18+00:00 2026-06-14T08:14:18+00:00

I have an Activity with EditText and Button widgets. Clicking the button prints an

  • 0

I have an Activity with EditText and Button widgets. Clicking the button prints an error message if the EditText is empty or calls setResult() to send the value back to another Activity which launched this one.

I am writing some simple unit tests to check that this interaction works. I have two different versions of the same test:

@UiThreadTest
public void testOkButtonOnClickWithNumber() {
    this.numberText.setText(Integer.toString(this.testNumber));
    Assert.assertTrue(this.okButton.performClick());
    Assert.assertTrue(this.activity.isFinishing());
}

public void testOkButtonOnClickWithUserInputNumber() throws Throwable {
    this.sendKeys(Integer.toString(this.testNumber));

    this.runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            Assert.assertTrue(NumberFilterTest.this.okButton.performClick());
        }
    });

    this.getInstrumentation().waitForIdle(new Runnable() {
        @Override
        public void run() {
            Assert.assertTrue(NumberFilterTest.this.activity.isFinishing());
        }
    });
}

As you can see, one test simply calls setText() on the EditText widget. The other uses sendKeys(). Is there a preferred best practice which of these two options to use during testing? Or should I keep both tests?

  • 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-14T08:14:19+00:00Added an answer on June 14, 2026 at 8:14 am

    I potentially have a new answer to an old problem, http://developer.android.com/tools/testing/testing_ui.html just released as part of adt21, if you are just starting out on android testing it is certainly worth looking at this.

    As for the actual question. Using sendKeys() is closer to what a user actually does and so if you had listeners on editing text or key press for example then they would get actually get fired. Typically this might not be an issue for you as you might not be using this functionality but it could bite you if you didn’t realise. Another example like this is how you are clicking your button, you are currently calling a the click method when the preferred way would be to send a touch event over the buttons location because that is actually what a user does.

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

Sidebar

Related Questions

friends, i have a EditText on simple activity with a button. when every i
i have made an activity at subscribe button, i have to send email to
I have implemented activity with edittext and button: After user entered a password and
I have an activity that shows some TextView s and EditText s, as well
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an Activity in Android, with two elements: EditText ListView When my Activity
I have created an edittext and a go button and a webview in single
I have four EditText and two buttons namely, save and review button. If i
I've tried converting an EditText value to string repeatedly, and have tried everything I
In my application I have an Activity Model in which i get a value

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.