Best practices for test data setup for a robust and concurrent test suite? #19867
Unanswered
penchef
asked this question in
Questions and Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi y'all! 🤠
Goals:
What are the best practices to setup your test data for (let's say ) a forum board app (user, login, discussion threads, etc...)*?
What I'm trying to do is to create the a distinct "sandbox" for each test, so that tests don't interfere with each other. By "sandbox" I mean a unique, e.g. user for the test + more relevant data (e.g. a new discussion thread + replies etc.). This would segregate each test's relevant data to a the unique user/thread and when a parallel test (or previous test) has created more threads/posts it doesn't matter to the current test.*
It's my understanding (and experience), that creating the setup data via UI interactions is not a good practice (slow, not relevant for the test, since user creation, login, and posting is tested in another test...), so my idea is to set up the data via API calls to my server.
My test would for example look like this:
before:
test "User can respond to an existing thread" :
Problems/Questions
cy.request
I have to fight CORS issues (CORS blocks the requests to my api server):ideally I'd like to write a
serverApi
library (with axios or whatever) which I can re-use not only for seeding test data for my web-app but also for my mobile client (plot twist!).I could write
cy.commands
(usingcy.request
which seem to bypass the CORS issues) to for all the data seeding, but then I'd have to do it all over again when I'm writing detox tests for the mobile app.I'm aware of disabling the SOP by default
{ "chromeWebSecurity": false, }
but this is limited to Chrome and I'm wary to throw cross browser testing out of the window when I'm about to make a big time investment into a cypress test suite.P.S.
I acknowledge that my CORS problem may not be applicable for most of y'all testing only one web-app, and that it is rooted in my goal #3 to re-use the test-data API client in multiple test suites.
With regards to the broader question of seeding the data: At a previous gig with a lot of teams and a complex Saas app, we had tremendous success to decouple teams/usecases and speeding up the test suite by seeding the data through a testApi and testing the web-app with Selenium. The testApi had all kinds of helpers (e.g. "get me a random user, with properties xyz, at a random company").
It enabled each test to be independent from the existing data of a test run, which is a must-have when you've got thousands of tests running in parallel. It also improved the debug-ability immensely, because a test was not dependent on a DB state and each test can be run quickly independently, without waiting for a length DB restore/reset, since it just creates all the data it needs.
Currently our server-api tests rely on a similar testApi, which interacts with the ORM directly (and is therefore not (easily) reusable in the cypress tests...
* in reality I'm testing a SaaS app with accounts + users + etc; accounts would serve as the segregating wall between each test
Edits: grammar + typos
Beta Was this translation helpful? Give feedback.
All reactions