How to test the textbox value in the Android JUnit test
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, pa开发者_开发百科ss);
}
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.
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.
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.
- Somewhere the text in your UI goes null.
- I think it should be
assertEquals(actualvar, whatyouexpect);
likeassertEquals(name, n1);
精彩评论