1

i have just created login screen project.I wrote the testcase for that.I dont know how to enter the text in textbox in JUnit test case. i just did like this

         public void testlogin() {
    final String n1 = "adithi";
    final String p1 = "adithi";
    String name, pass;
    editUname.clearComposingText();
    editPswd.clearComposingText();
    TouchUtils.tapView(this, editUname);
    sendKeys("adithi");
    TouchUtils.tapView(this, editPswd);
    sendKeys("adithi");

    activity.runOnUiThread(new Runnable() {

          public void run() {


            signinbtn.performClick();
          }
        }); 

        name = editUname.getText().toString();

        pass = editPswd.getText().toString();

    Log.e("name",name); 
    Log.e("Password",pass);
    assertEquals(n1, name);
    assertEquals(p1, pass);
}

the testcase result is

 junit.framework.ComparisonFailure: expected:<adithi> but was:<>
 at com.firstpageTest.Test.testlogin(Test.java:126)
 at java.lang.reflect.Method.invokeNative(Native Method)
 at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
 at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
 atandroid.test.ActivityInstrumentationTestCase2.runTest
    (ActivityInstrumentationTestCase2.ja
 atandroid.test.ActivityInstrumentationTestCase2.runTest
   (ActivityInstrumentationTestCase2.java:186)
  at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
  at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
  at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
  at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

please guide me.

1
  • jeez! You've edited your question and changed your code! I can sorta confirm UI text is going null somewhere after you performClick() Commented Mar 26, 2011 at 7:27

2 Answers 2

1

Its a simple one and I have done a small mistake in giving input to JUnit.we must give as

       sendKeys("A D I T H I");

It works now.

Sign up to request clarification or add additional context in comments.

Comments

0

Note. I'm not a Java person but..

Your test is failing because well its failing, your code is not running as you expected.It says expected:<Karthika> but was:<>

So the string from your UI is probably null. You're putting the string Karthika in the UI, then your test expects both strings to be adithi, but it fails saying it was null.

  1. Somewhere the text in your UI goes null.
  2. I think it should be assertEquals(actualvar, whatyouexpect); like assertEquals(name, n1);

3 Comments

i checked it,it is assertEquals(String expected,String actual);
Its going null or blank somewhere then. When/How is testlogin running? And what does performclick() do?
i think sendkeys("") is not the method to enter the textbox value.but i cant guess the method to give that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.