There's this sample repository, which showcases different Android testing practices. One of the apps is android-testing/unit/BasicSample, which is very simple and, among other things, checks the email field and for that purpose adds a listener like this:



And then on save it checks

     if (!mEmailValidator.isValid()) {  
                 mEmailText.setError("Invalid email");


Why not just have a simple utility class which will perform this check only when the Save button is pressed and not on each character change?


Because it can.

It's not overly taxing for the app to do this.

Perhaps there are other places where emails are validated, with UI that responds to the validation status changing. Having just one EmailValidator that listens to TextChange events and produces ValidationChange events is better than duplicating half of that work for a single check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.