Email field test cases
An email field fails in two directions: it turns away real addresses and lets broken ones through. These are the cases for both, each with a real address and what it usually breaks.
What should an email field be tested with?
With addresses that are valid but unusual, addresses that only look valid, the longest address the standard allows, and the capital letters and spaces a person types without noticing. A field that checks for “something, an @, something, a dot” fails some of them in one direction and some in the other. The sections below take them one at a time.
What do I check after each address?
The same four things every time:
- Can the person sign in with it? Sign up with the address, then sign in typing it the same way. A rule applied at one door and not at the other locks people out.
- Is it stored as typed? Or changed the same way everywhere, if the application changes it.
- Does the message name the problem? “Invalid email” for an address the application simply does not support sends the person away for good.
- Does mail reach it? An address the form accepts and the mail system refuses is the same defect, found later.
Which valid addresses do forms turn away?
Test the addresses real people have. Every one of these is legal, and each is refused by a surprising number of forms.
A perfectly valid address rejected by a surprising number of forms, which breaks the tagging people rely on.
emails-urls/plus-tag jan@zażółć.exampleInternationalised domains must be converted before use; a form that skips this rejects legitimate addresses.
emails-urls/unicode-domain "jankowalski"@example.comA quoted local part containing a space is legal and almost never handled.
emails-urls/quoted-local jan@example.com.A trailing dot is technically valid in a domain name and rejected by nearly every form.
emails-urls/trailing-dot-domainWhich broken addresses do forms accept?
Test the shortest mistakes. A validator that looks for a dot, or for an @ anywhere, lets these through.
The shortest invalid address that many simple validators accept.
emails-urls/double-at jan.example.comA domain typed into an e-mail field; accepted by validators that only check for a dot.
emails-urls/no-atHow long can an email address be?
The part before the @ can be 64 characters long, the most RFC 5321 allows. Test that length, then one character more, and check that the limit is enforced with a message, not by quietly cutting the address.
The boundary of the local part length; one character more must be rejected.
emails-urls/very-long-local 255 × aThe classic column width: one character short of the limit, exactly at it, and one over it are three different code paths.
length-bombs/len-255Capital letters and spaces
Test what a person types without noticing: an address in capitals, and a space copied along with it from a document or a message.
The local part is case-sensitive in principle and treated as case-insensitive in practice; uniqueness checks disagree between layers.
emails-urls/uppercase-local KowalskiLogin and e-mail comparisons differ between browser and server; the account is created but cannot be found.
whitespace/trailing-space KowalskiSorting puts the record at the top of every list, and exact-match search never finds it.
whitespace/leading-space abcdCharacter counters, comparison and deduplication see a different value than the human does.
whitespace/zero-width-space-x3And the website field next to it
A form with an email field often has a link field too. Test a link typed the way people type links, one that carries a password, and one long enough to break every column it is shown in.
A link typed the way people type links; storing it without a scheme produces a broken link everywhere it is used.
emails-urls/url-no-scheme https://user:pass@example.comA URL carrying credentials; displaying it anywhere reveals them, and storing it keeps them.
emails-urls/url-with-credentials https://example.com/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 2,000 code points in all, cut in the middleLong links break storage limits, logs and every column that displays them.
emails-urls/url-very-long https://example.com/zażółćNon-ASCII paths must be encoded; a layer that skips it produces links that work in one place and not another.
emails-urls/url-unicode-pathHow do I go through all of them quickly?
With the palette, one shortcut per address: choose the pack E-mail addresses and URLs, click the field, press AltShiftN , look at the result, and press it again for the next. When an address breaks something, AltShiftB copies a report block for the ticket. Getting started takes about two minutes.
For an automated test, nkb emit prints the pack as JSON, CSV or one value per line:
$ nkb emit emails-urls --format json > emails.json
Every address is on the page of the pack, with what a correct application does instead. For any other field, see text box test cases.