Adding a global script above Collection scope?

I’ve created a couple of basic test functions that I’m adding to the global scope in the Tests tab of the Collection property window and have Tests on requests do an eval on those functions. This works really great.

I now need to have the same set of Test functions on multiple Collections and that may turn into a maintenance hell as I now need multiple copies of the working code and it can become hard to trace bugs if two versions of the script becomes incompatible but are run on the same requests. My requests are moved between Collections and requests utilize these functions and pass parameters to them.

Is there a way to add this generic script a place above Collection Level to make sure I only ever have 1 version of this script to maintain?

Hey there!

So I think I understand your question. You want something like a workspace level tests/pre-request scripts area?

I can certainly see how that would be helpful and I see there is a feature request currently being tracked here.

In the meantime, perhaps there is a creative workaround that you could use that mocks a similar functionality?
I hope this helps! :smile:

Maybe a little late but yes. That is exactly what Im looking for :+1:

Not a full solution, but maybe an improvement …

I used the collection in this article as a reference.

I took all the test functions i’ve written and dropped them into a single js file. i set that up in s3 (or github, etc) and the first GET call in that collection downloads the file and sets the text response to a variable name.

then, i eval that global var at the test level. this is where it’s not a full solution to the original problem, but i think it simplifies the management of the test functions to a single place.

so far, i haven’t been able to do an eval at the collection level that works in the request level tests because of scoping, but starting every request level tests with eval(pm.globals.get("test_functions")); and then being able to access any functions there directly isn’t too painful.