Postman
The features described in this document are being deprecated. You can find more details about the current Testkube features to perform these functions here.
Testkube is able to run Postman collections inside your Kubernetes cluster so it can be used to test internal or external services.
- Default command for this executor: newman
- Default arguments for this executor command: run <runPath> -e <envFile> --reporters cli,json --reporter-json-export <reportFile>
Parameters in <> are calculated at test execution:
<runPath>
- path to the test files<envFile>
- path to the environment file set by--variables-file
<reportFile>
- path to the generated report json file
See more at "Redefining the Prebuilt Executor Command and Arguments" on the Creating Test page.
- Postman is a platform for designing, building, testing, and iterating APIs.
- Postman simplifies every step of the API lifecycle, making it easy for you to iterate and test your APIs by sending and inspecting responses, writing assertions to validate endpoints, or setting up logic to mirror your workflows.
Check out our blog post to follow tutorial steps for end-to-end testing of your Kubernetes applications with Postman.
Prerequisite: Example Postman testโ
Service Under Testโ
Let's assume that our SUT (Service Under Test) is an internal Kubernetes service which has
ClusterIP Service
created and is exposed on port 8088
. The service name is testkube-api-server
and is exposing the /health
endpoint that we want to test.
To call the SUT inside a cluster:
curl http://testkube-api-server:8088/health
Output:
200 OK
Example Postman collectionโ
In the following examples, we will use a simple Postman test that makes a GET request to http://testkube-api-server:8088/health
, and validates if response code equals 200.
You can find it in the Testkube repository: https://github.com/kubeshop/testkube/blob/main/test/postman/testkube-api-server-health.postman_collection.json
Exporting Postman collectionโ
If you'd like to use another collection you can create it in Postman, and export it to the .postman_collection.json
file by right clicking it and selecting Export.
Creating and Running a Testโ
A Postman collection consists of the single file, so the following test sources can be used to create a test:
- File
- Git file
- String
- Dashboard
- CLI
- Custom Resource
If you prefer to use the Dashboard, go to Tests and click the Add a new test
button. Then you need to fill in the test Name, choose the test Type (postman/collection
), and choose Test Source of your choice.
a) Creating a Test from Fileโ
If you have the collection you want to run saved locally, you can use File
as the test source. You can then select and upload it directly.
b) Creating a Test with Git fileโ
If you have a collection in the Git repository, you can use the Git file
source. Then, you need to fill in repository details:
- Git repository URI (in this case
https://github.com/kubeshop/testkube.git
) - branch (
main
) - path to Postman collection in your repository (in this case
test/postman/testkube-api-server-health.postman_collection.json
).
In this example, the repository is public; if the repository is private, you would need to additionally fill in Git credentials.
Running a Testโ
If you created a Test using any of the previous methods, you will be redirected to Test details. In order to run it, all you need to do is to click the Run button.
If you prefer using the CLI instead, you can create the test with testkube create test
.
a) Creating a Test from Fileโ
testkube create test --name postman-test --type postman/collection --file test/postman/testkube-api-server-health.postman_collection.json
Test created testkube / postman-test ๐ฅ
b) Creating a Test with Git fileโ
testkube create test --name postman-test --type postman/collection --test-content-type git-file --git-uri https://github.com/kubeshop/testkube.git --git-branch main --git-path test/postman/testkube-api-server-health.postman_collection.json```
```sh
Test created testkube / postman-test ๐ฅ
Running a Testโ
The test can be run using the testkube run test
command.
$ testkube run test postman-test
Type: postman/collection
Name: postman-test
Execution ID: 63fde0b3a862384f8f959239
Execution name: postman-test-6
Execution number: 6
Status: running
Start time: 2023-02-28 11:08:35.081273721 +0000 UTC
End time: 0001-01-01 00:00:00 +0000 UTC
Duration:
Test execution started
Watch test execution until complete:
$ kubectl testkube watch execution postman-test-6
Use following command to get test execution details:
$ kubectl testkube get execution postman-test-6
You can then check the execution results:
ID: 63fde715a862384f8f95923d
Name: postman-test-8
Number: 8
Test name: postman-test
Type: postman/collection
Status: passed
Start time: 2023-02-28 11:35:49.177 +0000 UTC
End time: 2023-02-28 11:35:57.203 +0000 UTC
Duration: 00:00:08
Repository parameters:
Branch: docs-postman
Commit:
Path: test/postman/testkube-api-server-health.postman_collection.json
Working dir:
Certificate:
running test [63fde715a862384f8f95923d]
๐ Initializing...
๐ Reading environment variables...
โ
Environment variables read successfully
RUNNER_ENDPOINT="testkube-minio-service-testkube:9000"
RUNNER_ACCESSKEYID="********"
RUNNER_SECRETACCESSKEY="********"
RUNNER_REGION=""
RUNNER_TOKEN=""
RUNNER_BUCKET="testkube-artifacts"
RUNNER_SSL=false
RUNNER_SCRAPPERENABLED="true"
RUNNER_GITUSERNAME=""
RUNNER_GITTOKEN=""
RUNNER_DATADIR="/data"
๐ฆ Fetching test content from git-file...
โ
Test content fetched to path /data/repo/test/postman/testkube-api-server-health.postman_collection.json
๐ Fetching uploads from object store testkube-minio-service-testkube:9000...
๐ Placing files from buckets into /data/uploads/ []
๐ Getting the contents of bucket folders [test-postman-test]
๐ Setting up access to files in /data
๐ฌ Executing in directory /data:
$ chmod
โ
Execution succeeded
โ
Access to files enabled
โ
Initialization successful
0xc0058e69c0
๐ Preparing test runner
๐ Reading environment variables...
โ
Environment variables read successfully
RUNNER_ENDPOINT="testkube-minio-service-testkube:9000"
RUNNER_ACCESSKEYID="********"
RUNNER_SECRETACCESSKEY="********"
RUNNER_REGION=""
RUNNER_TOKEN=""
RUNNER_BUCKET="testkube-artifacts"
RUNNER_SSL=false
RUNNER_SCRAPPERENABLED="true"
RUNNER_GITUSERNAME=""
RUNNER_GITTOKEN=""
RUNNER_DATADIR="/data"
running test [63fde715a862384f8f95923d]
๐ Preparing for test run