Skip to main content
Version: 2.0.0

Keploy CLI Commands

Usage

keploy [command] [flags]

You can use --help, -h flag for all the commands to see available flag options and their purpose.

Modes and Flags

Here are some examples of how to use some common flags:

ModeFlags Available
record-c, --command, --config-path, --containerName, -d, --delay, -n, --networkName, --passThroughPorts, -p, --path, --proxyport, --debug
test--apiTimeout, -c, --command, --config-path, --containerName, -d, --delay, --mongoPassword, -n, --net, --networkName, --passThroughPorts, -p, --path, --proxyport, -t, --testsets, --debug, -g, --generateTestReport, --removeUnusedMocks, --coverage, --goCoverage, --ignoreOrdering, --skip-preview
gen--sourceFilePath, --testFilePath,--coverageReportPath,--testCommand,--coverageFormat,--expectedCoverage,--maxIterations,--testDir,--llmBaseUrl,--model,--llmApiVersion
normailze-p, --path, --test-run, --tests
rerecord--test-sets, -t
config--generate,-p, --path

record

The record mode in Keploy allows the user to record Keploy testcases from the API calls. The recorded testcases and generated mocks are then saved in the keploy directory in the current working directory.

Usage:
keploy record [flags]
Available flags:
  • -c, --command string - Command required to start the user application.

    keploy record --command "node src/app.js"

    In the command above, node src/app.js is the command which starts the user application.

  • --config-path string - Path to the Keploy configuration file. The default is ".".

    keploy record -c "node src/app.js" --config-path "./config-dir/"

    In the above command, config-dir is the directory in the CWD where the Keploy configuration file keploy.yaml is stored.

  • --container-name string - Name of the docker container in which the user application is running.

    keploy record -c "docker compose up" --container-name "my-app-container"
  • -d, --delay uint - Delay in seconds to run user application. The default is 5 seconds.

    keploy record -c "node src/app.js" -d 10
  • - n, --network-name string - Name of the docker network in which the user application is running.

    keploy record -c "docker compose up" --container-name "my-app-container" -n "my-app-network"
  • --pass-through-ports uints - Ports of outgoing dependency calls to be ignored as mocks and passed through to the actual dependency. The default is no ports.

  • -p, --path string - Path to the local directory where the recorded testcases and generated mocks are to be saved.

    keploy record -c "node src/app.js" -p "./tests"

    In the above command, tests is the directory in the CWD where the recorded testcases and generated mocks are to be stored.

  • --proxy-port uint32 - Port to choose to run Keploy as a proxy. The default is 16789.

    keploy record -c "node src/app.js" --proxy-port 8080
  • --debug - To start recording testcases with debug mode enabled.

    keploy record -c "node src/app.js" --debug
  • rerecord - Record certain test-sets again

    keploy record -c "node src/app.js" --rerecord "test-set-0"

test

The test mode in Keploy allows the user to run the recoded testcases from the API calls and execute assertion. A detailed report is produced after the tests are executed and it's then saved in the yaml format in keploy/reports directory in the current working directory.

Usage:
keploy test [flags]
Available flags:
  • --api-timeout uint - Timeout in seconds for calling user application. The default is 5 seconds.

    keploy test -c "node src/app.js" --api-timeout 10
  • -c, --command string - Command required to start the user application.

    keploy test -c "node src/app.js"

    In the command above, node src/app.js is the command which starts the user application.

  • --config-path string - Path to the Keploy configuration file. The default is ".".

    keploy test -c "node src/app.js" --config-path "./config-dir/"

    In the above command, config-dir is the directory in the CWD where the Keploy configuration file keploy.yaml is stored.

  • --container-name string - Name of the docker container in which the user application is running.

    keploy test -c "docker compose up" --container-name "my-app-container"
  • -d, --delay uint - Delay in seconds to run user application. The default is 5 seconds.

    keploy test -c "node src/app.js" --delay 10
  • --mongo-password string - Authentication password for mocking MongoDB connection. The default password is "default123".

    keploy test -c "node src/app.js" --mongo-password "my-password"
  • - n, --network-name string - Name of the docker network in which the user application is running.

    keploy test -c "docker compose up" --container-name "my-app-container" -n "my-app-network" -d 9
  • --pass-through-ports uints - Ports of outgoing dependency calls to be ignored as mocks and passed through to the actual dependency. The default is no ports.

  • -p, --path string - Path to the local directory where the recorded testcases and generated mocks are saved.

    keploy test -c "node src/app.js" -d 10 --path "./tests"

    In the above command, tests is the directory in the CWD where the recorded testcases and generated mocks are saved.

  • --proxy-port uint32 - Port to choose to run Keploy as a proxy. The default is 16789.

    keploy test -c "node src/app.js" --proxy-port 8080
  • -t, --test-sets strings - To specify which specific testsets are to be executed. The default is all testsets.

    keploy test -c "node src/app.js" -t "test-set-1,test-set-3" --delay 10
  • --debug - To start executing testcases with debug mode enabled.

    keploy test -c "node src/app.js" --delay 10 --debug
  • -g, --generate-test-report - To generate the test report. The default is true.

    keploy test -c "node src/app.js" --delay 10 -g=false
  • --remove-unused-mocks - To remove unused mocks from mock file. The default is false.

    keploy test -c "node src/app.js" --delay 10 --remove-unused-mocks
  • --ignore-ordering - Ignore the order of elements in an array for a response, with the default value being true.

    keploy test -c "node src/app.js" --delay 10 --ignore-ordering
  • --skip-coverage - skip code coverage computation while running the test cases

  • --skip-preview - skip line by line code coverage preview but display the total coverage.

    keploy test -c "node src/app.js" --delay 10 --skip-preview
  • --jacoco-agent-path - Only applicable for test coverage for Java projects. You can override the jacoco agent jar by providing its path

gen

The gen cmd in Keploy allows user to generate unit tests using LLM Models.

Usage:
keploy gen [flags]
Available flags:
  • sourceFilePath - Path to the source file for which tests are to be generated.

  • testFilePath - Path where the generated tests will be saved.

  • coverageReportPath - Path to generate the coverage report.

  • testCommand - Command to execute tests and generate the coverage report.

  • coverageFormat - Type of the coverage report by default report is in "cobertura" format.

  • expectedCoverage - Desired coverage percentage by default it is set to be at 100%.

  • maxIterations - Maximum number of iterations for refining tests (default 5).

  • testDir - Directory where tests will be written.

  • llmBaseUrl - Base url of the llm.

  • model - Specifies the AI model to use by default it uses "gpt-4o" model.

  • llmApiVersion - API version of the llm if any.

normalize

The normalize cmd in Keploy allows user to change the response of the testcases according to the latest test run response that is executed by the user, this is useful when the API response of the testcases are changed due to code change or any other intentional change in the application.

Usage:
keploy normalize [flags]
Available flags:
  • -p, --path string - Path to the local directory where the recorded testcases and generated mocks are to be saved.

    keploy normalize -p "./tests"

    In the above command, tests is the directory in the CWD where the recorded testcases and generated mocks are to be stored.

  • --test-run string - by default normalization considers the latest test-run to change the response of the testcases but if user want to do it for a particular test-run this flag can be used.

    keploy normalize -p "./tests" --test-run "test-run-10"
  • --tests string - by default normalization considers all the testcases for normalization but if user want to normalize only few particular testcases this flag can be used

    keploy normalize -p "./tests" --test-run "test-run-10" --tests "test-set-1:test-case-1 test-case-2,test-set-2:test-case-1 test-case-2"

rerecord

The rerecordcmd allow user to record new keploy testcases/mocks from the existing test cases for the given testset(s)

Usage:
keploy rerecord -c "node src/app.js" -t "test-set-0"

templatize

The templatize cmd allows the user to templatize important fields in the testcases who's values are used in the request of testcases and that may change in the future.

Usage:
keploy templatize [flags]

config

The config command in Keploy is used to generate the Keploy Configuration File i.e. keploy.yaml. The generated configuration file is created in the current working directory.

Usage:
keploy config [flags]
Available flags:
  • --generate - Generate a new keploy configration file.

    keploy config --generate
  • -p, --path string - Path to the local directory where the Keploy Configuration File will be stored. The default is ".".

    keploy config --generate --path "./config-dir/"

    In the above command, config-dir is the directory in the CWD where the Keploy configuration file keploy.yaml is to be stored.

example

The example command in Keploy is designed to illustrate the usage of Keploy in various scenarios, showing its capabilities with different types of applications and setups. Below are examples for using Keploy with Golang, Node.js, Java, and Docker applications.

Usage:
keploy example [flags]
Available Flags:
  • --customSetup - Displays commands tailored for custom user-defined setups.