End-to-end testing is a nightmare. No, seriously, it’s one of my least favourite things to work on when I’m doing frontend or full-stack work. But they’re so. Darn. Useful. I’m not going to go into the benefits of end-to-end testing, but most of the time it’s the only type of testing I really do.
However, one of the trickiest parts of E2E testing a full-stack web app is managing database records. Tests will often need dummy data such as user accounts, transaction records, etc. etc., and can also create records during the test runs themselves.
It’s good practice to make sure these records are cleaned up at the end of the test cycle to avoid cluttering local databases and to allow you to run your tests repeatedly against long-running remote databases if needs be.
Creating the records you need is generally quite easy, though you can end up with a lot of boilerplate if you have to create lots of records in foreign tables (e.g. you need to create an order but you need a load of products first).