LoginActivity extends BaseActivity { public boolean check() { if (name.getText().toString().equals("")) { nameLayout.setError(getString(R.string.empty_username)); return false; } if (pwd.getText().toString().equals("")) { passwordLayout.setError(getString(R.string.empty_pwd)); return false; } return true; }  @Override boolean onOptionsItemSelected(MenuItem item); boolean check();  }
@SuppressLint("Assert") @Test public void clickLogin_emptyUsername(){ appCompatEditText.setText("123456"); activity.findViewById(R.id.login_submit).performClick(); assert(!activity.check()); }
@SuppressLint("Assert") @Test public void clickLogin_emptyPassword(){ emailEditText.setText("username"); activity.findViewById(R.id.login_submit).performClick(); assert(!activity.check()); }