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.
For example:
PS1: use
String.isEmpty()instead ofString.length() == 0.PS2: I suggest you use an array/List for your
EditTextinstead. Having one field for each is really a bad way of doing it. What happens if you add/remove oneEditText? You would need to scan all your code to find thatEditTextand remove it. Using an array/List you only need to update the array/List.