0

Recently I started writing tests for our API. However, I have faced some issues which I think it is critical to think at the start.

How should I structure my tests in terms of setup and cleanup phase(test data management)? Should I set necessary objects in a test in pre-req section to make the test independent on others? I followed this approach but I couldn't find a way to send requests synchronously.

On the other hand, I made a different approach which is basically using objects created in previous tests. But this makes the tests unmaintainable and very difficult to keep track of.

Are there any other approaches on test data management? Or should I do things differently?

0

pm.sendRequest is an asynchronous operation and you need to make the second request in the callback of the first one. This is the standard way to serially call two callback-based async operations in JavaScript.

pm.sendRequest(firstRequest, function (err, firstResponse)  {
  // add your extra logic here
  pm.sendRequest(secondRequest, function (err, secondResponse)  {
    // add your extra logic here
  });
});
  • I am doing that at the moment but I believe the code will get messy this way. Are you sure there are no other ways? Also what do you think about the strategy? Is it best practice for api tests to make them independent of each other? – batuarslan Aug 22 at 11:55
  • Sure, IMO they need to be independent of each other. Didn't find any other way yet (except maybe running them in docker locally with preconfigured database which has always the same state when starting and then it's deleted after test run). – Michal Dobrzycki Aug 22 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.