Run a collection with a mock
You can redirect collection requests to a mock using the Mock tab in the Collection Runner. For each base URL in the collection, you can select a different mock. This lets you test how your service behaves without calling real services.
Select a mock for a collection run
Run a collection with a mock to test your service against mock responses. When you start the run, Postman redirects requests matching the selected base URL to the mock.
- Click
Items in the left sidebar.
- Click Collections and select the collection you want to run.
- Click
Run.
- Select Functional, then select Local, Schedule, or Postman CLI.
- Configure the collection run settings as needed.
- Click the Mock tab.
- For each base URL in the collection, use the Select mock dropdown list to choose a mock. To create a new mock, select
Create mock from the dropdown list. Postman identifies all requests using that base URL and uses them in the mock’s implementation.
- (Optional) Next to each mock dropdown list, select a scenario with specific request handling code, endpoints, and conditions. To learn more about scenarios, see Manage scenarios in a mock.
- Click Start run or Schedule Run. To run the collection with the Postman CLI, copy the generated commands.
You can also use the --use-mock option with the postman collection run command to redirect requests to a mock directly from the Postman CLI.
View mock events
After the collection run completes, you can view the Mock events tab in the run results. The Mock events tab shows events associated with the mock, including applied scenarios, response code, and tests that ran.
Learn more about viewing collection run results.