Tutorial :How to prepare Email Validation test case?



Question:

HI ,

I am writing a java program to validate email addresses. This program use Pattern class to validate the input string against the Regex pattern. I have procured Regex Pattern for the email validatation and my program is successfully working.

Now, I see some wrong email addresses in my database(Email delevery fails to these addresses.), So, i decided to prepare a test case that will run a validation on the handfull of email addresses list. I want this list to have all possible cases for a valid email address and invalid email address.

I am wondering if some has prepared email validatation test case before? If so Please Guide me to have this test case prepared with me?

Regards, VSD


Solution:1

This article contains some regexps which cover valid addresses.

There are no test cases, though. In your case, I suggest to try the usual approach: Take a couple (2-3) valid and invalid addresses and test that. If you find your code to accept an illegal address or reject a valid one, then extend the test.


Solution:2

Dominic Sayers has collected test cases from Cal Henderson, Dave Child, Phil Haack, Doug Lovell, RFC 5322 and RFC 3696, 222 test addresses in all (see this previous answer).

His stuff is available on his blog in RFC-compliant email address validator (in the results and analysis).

Just keep in mind that there is no perfect solution using regex, the grammar is too complex for that.

See also


Solution:3

may this site http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html will provide you some help. But the only way to validate emails is to try to send one.


Solution:4

It sounds a lot like the emails are of the correct form but aren't actually registered. There's no way to check for that without actually emailing these addresses.

Is the problem that the emails aren't properly formed (eg asdf@foo) or that they're not registered accounts (emails getting bounced or ignored by the mailserver)?


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »