Skip to content

Generate your first test suite (CLI)

This tutorial generates tests from an OpenAPI spec using the CLI.

1) Get the CLI

Install via npm (recommended):

npm install -g @openapi-testgen/cli

Or run without installing:

npx @openapi-testgen/cli --help

For native binaries and building from source, see Installation.

Verify installation:

openapi-testgen --help

2) Generate template-based tests

openapi-testgen \
  --spec-file path/to/openapi.yaml \
  --output-dir ./build/generated-tests \
  --generator template \
  --generator-option templateSet=restassured-java \
  --generator-option templateVariables.package=com.example.generated \
  --generator-option templateVariables.baseUrl=http://localhost:8080

This generates Java test classes using RestAssured that you can run with JUnit.

3) Generate JSON/YAML test suites

For data-driven testing or custom frameworks:

openapi-testgen \
  --spec-file path/to/openapi.yaml \
  --output-dir ./build/out \
  --generator test-suite-writer \
  --generator-option outputFileName=openapi-test-suites.json

This generates a JSON file containing test case definitions that can be consumed by any test runner.

Next steps