3

In the process of testing, we all do create test (dummy) data on different env levels like (dev, QA, cluster & sometimes staging). When you have a small number of tests everything is fine, but when you have a large number of tests and when they are executed in parallel as in my case tests are interfering because they're using the same data.

So my goal here is to isolate every test and make them independent from other tests. I'm planning to create unique data for each test and every test will work/manipulate with its own data.

The question is how do I clean up all of the data that were created during test execution, so tests will be able to create the same data each time they are executed? Has anyone else been through such a case and found a good solution for this?

My testing framework is built on Java, using Cucumber with Serenity BDD and RestAssured (for testing Web UI and API).

p.s there's a solution I have in mind currently and that's to keep track (something like using session variables) of every object I create whether using Web UI or API and on the final step of every test (by using '@After' method) using API to get the ID's of every object I've created and then do a delete Rest request to delete these items which will delete them from the database too.

Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
One Dot
  • 71
  • 1
  • 4
  • I don't know how viable it would be for you, but using a temporary database like h2, I don't know how serenity works if I'm honest, also if you need to create files use the functions of creating temporary files, and if not after executing the method , use erase functions. – Adrian Lagartera Jul 03 '20 at 09:57
  • It depends on what solution you expect and what type of tests you want. For unit-tests I will move with Fakes and implement database communication layer via simple Java structures (such List, Set). For integration testing, I will consider using https://www.testcontainers.org/ – Dmytro Chasovskyi Jul 03 '20 at 10:48
  • @DmytroChasovskyi my automation project lives outside the backend (bsl code) so I'm not writing unit neither integration tests. Currenlty I'm only wriitng E2E API & UI tests. – One Dot Jul 03 '20 at 12:10
  • @AL how does one use a temporary DB in my case when I'm using the API directly? – One Dot Jul 03 '20 at 12:13
  • 1
    Have you thought about using docker? – Vinícios Rodrigues Jul 10 '20 at 00:16
  • @ViníciosRodrigues how would one use docker in this case? I'm new to docker, but if you might clearify it for me I will give it a shot. – One Dot Jul 16 '20 at 15:55
  • You create an image of the database with the necessary data and whenever you run the container, the database will boot in the initial context, this allows you to run the tests countless times always with the same context. – Vinícios Rodrigues Jul 24 '20 at 20:33

0 Answers0