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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:25:50+00:00 2026-06-18T02:25:50+00:00

Hii i am new to junit test for android so my question is i

  • 0

Hii i am new to junit test for android so my question is i have 6 EditText fields and one Button by pressing the Button it will check weather the field length of EditText fields are zero,if they are zero then it will show a Toast and otherwise it will go to another Activity so here is the my code

Button.OnClickListener okListener = new Button.OnClickListener() {
        public void onClick(View arg0) {
            if(text1.getText().toString().length()==0 || text2.getText().toString().length()==0||text3.getText().toString().length()==0||   text4.getText().toString().length()==0||text5.getText().toString().length()==0||    text6.getText().toString().length()==0||txt7.getText().toString().length()==0||txt8.getText().toString().length()==0){
                Toast msg = Toast.makeText(ActivityOne.this,
                        "Field shouldn't left blank", Toast.LENGTH_LONG);
        msg.show();
}

i got to know how to write the Testcases for if statement anybody has idea about how write Testcases for Toast. using Robotium also not a issue.

  • 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-18T02:25:52+00:00Added an answer on June 18, 2026 at 2:25 am

    For example:

    // JUnit class
    Button.OnClickListener okListener = new Button.OnClickListener() {
                public void onClick(View arg0) {
                    assertTrue(text1.getText().toString().isEmpty() || 
                                text2.getText().toString().isEmpty()||
                                text3.getText().toString().isEmpty()||
                                text4.getText().toString().isEmpty()||
                                text5.getText().toString().isEmpty()|| 
                                text6.getText().toString().isEmpty()||
                                txt7.getText().toString().isEmpty()||
                                txt8.getText().toString().isEmpty());
        }
    
    public void testButtons() {
        yourButton.setOnClickListener(okListener);
        okListener.onClick(yourButton);
    }
    

    PS1: use String.isEmpty() instead of String.length() == 0.

    PS2: I suggest you use an array/List for your EditText instead. Having one field for each is really a bad way of doing it. What happens if you add/remove one EditText? You would need to scan all your code to find that EditText and remove it. Using an array/List you only need to update the array/List.

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

Sidebar

Related Questions

hii everyone am sowmya am brand new to android please can any one help
hii every one i am brand new to obj c, i have did a
Hii....i am new to iPhone programming..Can anybody help me out please i have an
hii every one i am new to iphone , can any one tell me
Hi I am new to php eclipse and I have a question about my
Hii I am New to Android Development an i am trying this simple application
Hi i am new to android and i have created a app which uses
Hi I am new to android and I am doing one simple application. My
Hi I have the following problem when running junit test. org.hibernate.HibernateException: No Session found
Hii....i am new to iPhone programming..Can anybody help me out please i have an

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.