Categories
Automated Testing e2e Testing

Generating data for e2e automated tests

I generally prefer creating e2e automated tests that generate their own data so that the test is repeatable, more deterministic and less dependent on external data and factors which can change.


When writing automated e2e tests that generate data I’ve found there are two common approaches:

  1. Generate static data: this data remains the same between test runs2.
  2. Generate random data: this data can change each test run

An example of static data for a test would be:

const ContactModel = function () {
  return {
    firstName: 'Sammy',
    lastName: 'Snake',
    phoneType: 'MOBILE',
    phoneNumber: '0422888444',
    emailType: 'PERSONAL',
    email: 'sammy.snake@hotmail.com',
    type: 'INDIVIDUAL'
  }
}

and the same example using randomised data:

function pick (list) {
  return list[Math.floor(Math.random() * list.length)]
}

const ContactModel = function () {
  const firstName = pick(['Aaron', 'Becca', 'Charlie', 'Donna', 'Eckbert', 'Fred', 'Graham', 'Holly', 'Ignatius', 'Josephine'])
  const lastName = pick(['Aardvark', 'Bear', 'Cat', 'Dog', 'Eagle', 'Fox', 'Gorilla', 'Horse', 'Iguana', 'J'])
  return {
    firstName: firstName,
    lastName: lastName,
    phoneType: 'MOBILE',
    phoneNumber: `+${Math.round(Math.random() * 9999999999999)}`,
    emailType: 'PERSONAL',
    email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@${pick(['hotmail.com', 'yahoo.com', 'gmail.com', 'aol.com'])}`,
    type: 'INDIVIDUAL'
  }
}

Generally speaking I will choose static data when writing automated e2e tests as it’s more repeatable and consistent, however I still commonly see random generated data being used in automated e2e automated tests.

I think the reason is that varying data is a good exploratory testing technique to find bugs, however automated e2e tests aren’t about exploring functionality but rather ensuring the functionality continues to work as expected (regression testing).

They don’t have to be completely separate concepts though, my checked-in automated e2e test can use static data so it’s consistent and repeatable, but I could modify the same automated test to use randomly generated input which I could specifically run looped for a large number of iterations to assist me with my exploratory testing and try to find bugs around input.

I’ve found that great testers uses automated tests as a technique to assist them with their exploratory testing.


What’s your preferred approach? Do you generate static or randomised data or use existing data for your automated e2e tests?

One reply on “Generating data for e2e automated tests”

Hi Scott,

Yes, I definitely prefer static data over dynamic. There are some cases for example to do with time checking that dynamic can help to uncover problems in the future.

Primarily I use data created by the software itself, because even if we are using static data created by automation to it seems we are just testing the automation rather than the software?

Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *