Automating CSV Data for Reliable API Testing
Recently, I tackled a practical challenge in my API automation work and wanted to share both the problem and my solution — in case it helps someone out there in a similar boat!
🚧 The Problem
In my current project, one of our APIs is responsible for onboarding users through the upload of CSV files. This API checks the uploaded data against existing backend records and rejects the entire upload if it detects any duplicates
Now, here comes the tricky part: My test needs to run repeatedly (automated), but each time it runs with the same CSV file, the API fails because duplicate entries already exist in the system.
Two workarounds were initially proposed:
I knew we could do better.
💡 My Thought Process
Instead of changing the whole database or managing tons of files manually… Why not generate unique data programmatically for every test run?
That way:
🛠️ The Solution I Built
I created an R&D project to build an automated solution that:
⚙️ Technologies Used:
Recommended by LinkedIn
The Result
My Key Learnings
What’s Next?
This R&D setup is now complete and validated. I’ll be integrating it into our production test automation pipeline soon.
LIVE API + Repository Link
☑️API Endpoint: https://playing-with-api.onrender.com/docs/
📂Github Repo: https://github.com/Sisadia/playing-with-api
Why I'm Sharing
This might seem like a small challenge, but it's a real-world pain point in test automation — and solving it with code gave me the flexibility to focus on testing logic rather than data cleanup.
Happy testing! ✨
My two cents: if I understand the code correctly, you save the data to the database during each test run and delete it in the teardown process. Therefore, using Faker.js to generate fresh data each time seems unnecessary to me. Reimporting the same CSV/data already gives you a unique dataset for every test execution.