Where is the best place to set global functions for tests?

I’m trying to set some global functions for my tests, right now I have them in the collection “Pre-request Scrips” however these get run every time I make a request. Is there another place to place them that would make more sense?

Hi there @kristianbrasel

As you said, collection-level pre-request scripts will execute prior to every request in the collection. Similarly, you could run your scripts at the folder- or request-level. This controls your scope a bit, but it’s still not accessible “globally”.

It’s not quite recommended, however you can also save your function as a variable (global, environment, collection, or whatever scope you choose). And then eval() it when needed. This gives you a little more flexibility to control your scope and allows you to share with team members if you wanted to. For example, global variables are available within a workspace. Environment variables are portable across collections. And so on.

If none of this is quite what you’re looking for, feel free to chime in on feature requests with specifics of your use case, like this.

1 Like