-4

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:

mEmailText.addTextChangedListener(mEmailValidator); 

https://github.com/googlesamples/android-testing/blob/923a02c2bee18e6315c5a71c8352a4c252cfa862/unit/BasicSample/app/src/main/java/com/example/android/testing/unittesting/BasicSample/MainActivity.java#L68

And then on save it checks

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

https://github.com/googlesamples/android-testing/blob/923a02c2bee18e6315c5a71c8352a4c252cfa862/unit/BasicSample/app/src/main/java/com/example/android/testing/unittesting/BasicSample/MainActivity.java#L95

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?

2

1 Answer 1

3

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.