Course outline
Test data generator
Names, emails, dates, numbers and text that break careless code, each with the reason to try it, the same again with the same seed.
Forms are often tested with "John Smith" and "test@test.com", and then a customer called Zoë O'Brien cannot sign up. Code breaks on the values nobody typed during testing: an accent, an apostrophe, a leap day, a number just past a limit, a name written right to left, an emoji.
Choose a kind of data, how many values you want and a seed. Each value comes with the reason it is worth a test. The same seed always gives the same values, so a test that failed can be run again with exactly the data that broke it. Download them as CSV or JSON for your tests.
Use the tool
The same seed gives the same values.
| Value | Why test it |
|---|---|
Yusuf Lind | a plain name |
Kwame Kowalski | a plain name |
José Sato | accents, an apostrophe or a hyphen |
Kwame Smith-Jones | accents, an apostrophe or a hyphen |
Priya Haddad | a plain name |
Omar Kowalski | a plain name |
Daniel Núñez | accents, an apostrophe or a hyphen |
José Lind | accents, an apostrophe or a hyphen |
Grace Ishikawa | a plain name |
Tomás Haddad | accents, an apostrophe or a hyphen |
How the method works
Edge values come from what is known to break: dates where the calendar changes (leap days, the last day of a month, years before 1900 and after 2038), numbers at the limits of the types computers store (32-bit integers, the largest number JavaScript holds exactly), and text that changes length or direction, or that looks like code.
Names and valid emails are drawn at random from small lists, with a seeded generator (mulberry32): random enough to vary your tests, repeatable when you need it. The invalid emails, dates, numbers and text come from fixed lists, in order of how often they find bugs. None of this is real data.
- Choose the kind of data an input takes, and how many values you need.
- Use the values in your test cases: the "why" column says what each one should prove.
- Keep the seed with a failing test, so it can be repeated with the same values.
A worked example on Cedar Books
The Cedar Books sign-in takes an email address (REQ-01). These invalid addresses should each be refused with the same clear message, and none should reach the server as a valid sign-in:
| Value | Why test it |
|---|---|
plainaddress | no @ |
@example.com | nothing before the @ |
lina@ | nothing after the @ |
lina@example | no dot in the domain |
lina@@example.com | two @ |
lina haddad@example.com | a space before the @ |
lina@exa mple.com | a space in the domain |
lina..haddad@example.com | two dots in a row |
Run the list through the sign-in form and through the API: a form that checks the address while the API does not is a bug waiting for the first script. The same goes for the review comment field, with the text kind.