Before learning little, most of their own junit test again can, not how to use postman test.

But this time I was working with my teammates on a project that separated the front and back ends, so I had to use postman.

The token was used in the write permission. Procedure

A token is returned after a successful login, and the token returned is different each time you log in. At first, it is for security, not for the trouble of testing.

Not postman at first, only to copy every time, let me directly explode. I feel so repeated things, do not have to do so silly.

And then this blog came into being. 😂

once

My login interface

The data returned looks like this.

Every time I access other interfaces with permissions, I need to bring this token to request.

The way I used to write it

After the improvement:

The next step is to set the environment variables and use them.

When I click it, it looks like this

Let’s go ahead and hit Add

Then we select the name of the environment variable we just wrote in the upper right corner and click into Tests. We need to write some scripts in Tests to store the values into the environment variables.

Here’s the point.

My data format:

Pm.response.json ().data.token set to userToken key
pm.environment.set("userToken", pm.response.json().data.token);
Copy the code

At this point we look at the environment variables in the upper right corner and we’ve already saved them.

Specific use:

Here’s how to use it.

It used to be written that way.

You have environment variables and they’re dynamic and you don’t have to change them every time you refresh them.

Some commonly used request data can also be stored directly in environment variables. You can do this with userId, or whatever else is commonly used. Can save a lot of things. There is a set of tests for each set of environment and the set of environment variables selected is the set of environment variables used

self-talk

The more you know about something, the more ridiculous you feel about your former self.