I’m currently trying to optimize my tests in Postman and wanted to use the Tests tab of my Collections for test I run almost all the time for each request.
I was just wondering if you guys knew why I can’t set a jsonData directly in this tab. Instead I have to call this variable in the Tests tab for all my requests.
I don’t see where you are consuming jsonData in your screenshot. I see it is being declared, but not actually used.
Are you able to post your code that is actually failing?
I was able to get it collection tests working using two different methods:
The screenshot I attached was more to show how I want my global template in my collection to be.
jsonData depends on what the response of my request is so it’s normal (to me) not to use it at a collection level.
Here’s an example for a request :
The best idea I could come up with is to stuff it into a collection variable on the collection test script, and then reference that in the request-level test script.
But that still requires you to declare a variable in the test script and set it equal to the collection variable value, and in fact would be a longer line of code than just declaring it in the test script as const jsonData = pm.response.json();
So tl;dr I don’t think there’s a way to automatically declare and assign to a variable for every request test script (at least not a way that will have any practical benefit)