Skip to main content

Capture Traffic from Newman

Running tests through Optic with Newman#

Optic helps you run your existing Newman tests against your project, adding in schema checks for every request and response seen. The tests you have today can help establish the baseline behavior of your API and assert that your API is behaving according to the specification Optic has recorded. Tests are run with a single command:

api run test


Before running tests, you'll need to integrate with your current project. We recommend following the instructions to set up your framework's api start command, and to use a middleware integration where available:

Integrating your Newman tests manually#

If your project is integrated with Optic using middleware, configuring a test task is as easy as configuring a start task. If using a middleware integration is not feasible, Optic can use your working start task to make running your tests through your proxy integration easy.

Configuring Optic to run your tests#

The middleware integration will assure Optic sees your traffic, no matter if it is sent interactively or through a Newman test collection. We recommend a test task, which will tell Optic to use the previously defined start task with the useTask parameter and run our test with the command parameter. For example, if you would normally run a Newman collection with newman run collection.json --environment environment.json, your test task would be defined in optic.yml like this:

name: "todo-js"tasks:  start:    command: <your start command>  test:    useTask: start    command: newman run collection.json --environment environment.json