Skip to content

Commit c64b4ac

Browse files
Tvisha Rajiactions-user
authored andcommitted
API testing
1 parent 0968460 commit c64b4ac

File tree

6 files changed

+361
-3
lines changed

6 files changed

+361
-3
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
id: about-api-testing
3+
title: What is API testing?
4+
sidebar_label: What is API testing?
5+
description: This section documents what is API Testing and why we need it
6+
tags:
7+
- API testing
8+
- API mocks
9+
- generate test cases
10+
- test automation
11+
keywords:
12+
- api testing
13+
- api mocks
14+
- automated testing
15+
- ai testing
16+
- keploy
17+
- Gemini
18+
- OpenAI
19+
---
20+
21+
# 📘 What is API Testing?
22+
23+
**API Testing** is a type of software testing that focuses on verifying that **Application Programming Interfaces (APIs)** function as expected. Instead of testing the UI, API tests validate business logic, data responses, and the performance of an application’s backend services.
24+
25+
APIs act as the _bridge_ between different software systems — enabling communication and data exchange. Testing ensures these bridges are **reliable, secure, and performant**.
26+
27+
## ✅ Why Do We Need API Testing?
28+
29+
| Reason | Description |
30+
| --------------------------------- | --------------------------------------------------------------------------------------------------------- |
31+
| **1. Early Bug Detection** | API testing is usually done before UI testing, allowing faster detection and resolution of critical bugs. |
32+
| **2. Improved Test Coverage** | Validates all layers of the application including edge cases, error codes, and data responses. |
33+
| **3. Faster Execution** | API tests are faster than UI tests, enabling quicker feedback loops in CI/CD pipelines. |
34+
| **4. Language-Agnostic** | APIs can be tested independently of the frontend technology — enabling broader automation. |
35+
| **5. Enhanced Security** | Validates authentication, authorization, and data privacy mechanisms. |
36+
| **6. Enables Continuous Testing** | Ideal for automated pipelines to ensure every build meets quality standards. |
37+
38+
## 🧪 What Do We Test in an API?
39+
40+
- Request & Response Validation
41+
- Status Codes (200, 400, 500, etc.)
42+
- Data Format (JSON, XML, etc.)
43+
- Authentication & Authorization
44+
- Load and Performance
45+
- Edge Cases and Error Handling
46+
47+
## 🔍 Types of API Testing
48+
49+
| Type | Description |
50+
| ----------------------------------- | ------------------------------------------------------------------------ |
51+
| **Functional Testing** | Ensures the API performs expected functions correctly with valid inputs. |
52+
| **Validation Testing** | Verifies the API meets business and technical requirements. |
53+
| **Load Testing** | Evaluates how the API handles a large volume of requests. |
54+
| **Security Testing** | Checks for vulnerabilities, data leaks, and access control. |
55+
| **Error/Negative Testing** | Validates behavior when given invalid inputs or unexpected conditions. |
56+
| **Regression Testing** | Ensures recent changes haven't broken existing functionality. |
57+
| **Runtime and Reliability Testing** | Confirms the API's stability and availability during sustained use. |
58+
59+
## ⚠️ Common Challenges in API Testing
60+
61+
- Lack of proper API documentation
62+
- Handling dynamic responses and tokens
63+
- Managing large test data and scenarios
64+
- Testing across multiple environments (dev, staging, prod)
65+
- Ensuring version compatibility and backward support
66+
- Automating complex workflows involving chained API calls

versioned_docs/version-2.0.0/running-keploy/api-test-generator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: api-test-generator
3-
title: Keploy API Test Generator
3+
title: API Test Generator
44
sidebar_label: API Test Generator
55
description: This section documents usecase of Keploy's API Test Generator
66
tags:
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
id: best-practices-api-testing
3+
title: Best Practices for API testing
4+
sidebar_label: Best Practices
5+
description: This section documents what best practices can be followed while performing API testing
6+
tags:
7+
- API testing
8+
- API mocks
9+
- generate test cases
10+
- test automation
11+
- Best Practices
12+
keywords:
13+
- api testing
14+
- api mocks
15+
- automated testing
16+
- ai testing
17+
- keploy
18+
- Gemini
19+
- OpenAI
20+
---
21+
22+
## 🛠️ Best Practices in API Testing
23+
24+
API testing ensures the reliability, security, and performance of your application's backend services. To build robust, scalable test suites, here are the best practices you should follow:
25+
26+
### ✅ 1. Define Clear Test Objectives
27+
28+
- Understand what you're testing — functionality, security, performance, or error handling.
29+
- Align tests with business logic and expected user workflows.
30+
31+
### 🧪 2. Cover Both Positive and Negative Scenarios
32+
33+
- Validate how the API responds to correct input.
34+
- Intentionally send malformed, missing, or unauthorized requests to verify error handling and status codes.
35+
36+
### 🔄 3. Automate Repetitive Tests
37+
38+
- Integrate API tests into your CI/CD pipeline.
39+
- Automate regression tests for each deployment or commit.
40+
41+
## 🗃️ 4. Use Data-Driven Testing
42+
43+
- Store request and response data externally (e.g., JSON files or CSV).
44+
- This keeps test logic clean and improves reusability.
45+
46+
## 🔐 5. Test Authentication and Authorization
47+
48+
- Validate token generation, expiration, and refresh flows.
49+
- Confirm users cannot access resources outside their scope.
50+
51+
### 🕒 6. Measure Performance and Response Times
52+
53+
- Ensure APIs meet SLAs under normal and load conditions.
54+
- Monitor response time, throughput, and error rates.
55+
56+
## 🧩 7. Validate Response Structure and Schema
57+
58+
- Check if all fields exist and are in the correct format (JSON schema validation).
59+
- Flag any unexpected keys or missing data.
60+
61+
### 🌍 8. Handle Environment Configurations
62+
63+
- Avoid hardcoding endpoints and credentials.
64+
- Use environment variables or configuration files for flexibility across dev, staging, and prod.
65+
66+
### 📦 9. Use Mocks and Stubs When Needed
67+
68+
- Isolate APIs under test from third-party dependencies.
69+
- Simulate edge cases or failure scenarios not easily reproducible in production.
70+
71+
### 📈 10. Track and Version API Tests
72+
73+
- Keep your API test suite in version control (e.g., Git).
74+
- Ensure tests are updated as the API evolves (versioning, deprecations).
75+
76+
### 🔁 11. Chain Requests for Workflow Validation
77+
78+
- Simulate real-world flows (e.g., user signup → login → perform action).
79+
- Maintain session or token data across calls.
80+
81+
### 📊 12. Add Clear Logging and Reporting
82+
83+
- Output test name, request payload, status code, and failure reason.
84+
- Use structured reports for better traceability in CI/CD tools.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
id: test-generate
3+
title: What is API testing?
4+
sidebar_label: Generate Tests
5+
description: This section documents what is API Testing and why we need it
6+
tags:
7+
- API testing
8+
- API mocks
9+
- generate test cases
10+
- test automation
11+
keywords:
12+
- api testing
13+
- api mocks
14+
- automated testing
15+
- ai testing
16+
- keploy
17+
- Gemini
18+
- OpenAI
19+
---
20+
21+
# 🧪 AI-Powered API Test Suite Generation
22+
23+
Keploy enables you to automatically generate **comprehensive API test suites** for your application using AI, based on live requests, API schemas, and supporting documentation.
24+
25+
## 🚀 Create API Tests in 4 Simple Steps
26+
27+
### 1️⃣ Create a New App
28+
29+
Start by creating a new test project for your application:
30+
31+
- Click on **"Create New App"**
32+
- Give it a name that matches your app/module
33+
- Optionally provide a description
34+
35+
### 2️⃣ Input URL or Endpoint
36+
37+
Provide a base URL or a specific API endpoint you want to test:
38+
39+
This helps Keploy identify where the API requests are sent and initiate context-aware test generation.
40+
41+
### 3️⃣ Add Test Inputs
42+
43+
#### 🔐 Authentication (Optional)
44+
45+
If your API requires authentication, make sure you:
46+
47+
- Add API keys or bearer tokens in headers
48+
- Or include auth flows via test inputs below
49+
50+
#### 📎 Paste cURL Snippets _(Recommended: 3–5)_
51+
52+
Add working `curl` commands representing real user flows. These help the AI infer request types, payloads, and expected outcomes.
53+
54+
```bash
55+
curl -X POST https://your-api.com/login -d 'username=john&password=secret'
56+
57+
curl -X GET https://your-api.com/users
58+
59+
curl -X PUT https://your-api.com/users/1 -d 'username=john&role=admin'
60+
```
61+
62+
### 📄 Swagger / OpenAPI Schema
63+
64+
Paste your OpenAPI (Swagger) spec in either **YAML** or **JSON** format.
65+
This schema provides a contract for how endpoints behave and enables accurate, schema-driven test generation.
66+
67+
### 4️⃣ Upload Supporting Resources (Optional but Valuable)
68+
69+
Enhance test accuracy by uploading documentation such as:
70+
71+
- 🧾 **API Docs** (Postman collections, Swagger files)
72+
- 💻 **Code Snippets**
73+
- 📄 **PRD/BRD documents**
74+
- 🗂 **Feature briefs or requirement docs**
75+
76+
These help Keploy better understand the intended logic and behavior of each endpoint.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
id: test-run-reports
3+
title: What is API testing?
4+
sidebar_label: Test Report generation
5+
description: This section documents what is API Testing and why we need it
6+
tags:
7+
- API testing
8+
- API mocks
9+
- generate test cases
10+
- test automation
11+
keywords:
12+
- api testing
13+
- api mocks
14+
- automated testing
15+
- ai testing
16+
- keploy
17+
- Gemini
18+
- OpenAI
19+
---
20+
21+
# 🧪 Keploy Test Run Reports
22+
23+
Easily track and manage the outcome of your API test runs with detailed reporting on test executions, results, and creators.
24+
25+
## 🔍 Search Test Run Reports
26+
27+
Use the search bar to filter reports by Report ID, creator email, or status.
28+
29+
### 📋 Test Report Summary
30+
31+
- Report ID
32+
- Created At
33+
- Creator
34+
- Total Tests
35+
- Passed
36+
- Failed
37+
- Status
38+
39+
## 🧩 Test Suites
40+
41+
Manage and fine-tune your test suites for each API endpoint. You can edit request inputs, response expectations, and assertion types.
42+
43+
### ✏️ Editable Test Cases
44+
45+
Each test case can be modified to:
46+
47+
- Change the **request payload**, headers, or query parameters
48+
- Edit or update **expected response bodies**
49+
- Select or modify **assertion types**
50+
51+
### 🧪 Supported Assertion Types
52+
53+
| Assertion Type | Description |
54+
| ------------------ | -------------------------------------------------------------- |
55+
| `statusCode` | Asserts the HTTP status code matches expected (e.g., 200, 404) |
56+
| `bodyContains` | Checks if the response body includes specific text or keys |
57+
| `jsonEquals` | Validates deep equality of the JSON response |
58+
| `headerMatch` | Asserts presence or value of specific response headers |
59+
| `schemaValidation` | Validates against OpenAPI/JSON schema if available |
60+
| `custom` | User-defined scripts or match rules |
61+
62+
#### ➕ Example Test Case Structure (YAML)
63+
64+
```yaml
65+
- testName: Get All Users
66+
method: GET
67+
endpoint: /users
68+
expectedStatus: 200
69+
assertions:
70+
- type: statusCode
71+
- type: bodyContains
72+
value: "username"
73+
- type: jsonEquals
74+
expected:
75+
- id: 1
76+
username: john_doe
77+
```
78+
79+
### 🧱 Edit Test Step
80+
81+
Easily customize individual test steps to simulate real-world API usage and validate your app’s behavior under different conditions.
82+
83+
#### 🔧 Request Details
84+
85+
Update the request configuration for each test case:
86+
87+
- **Name:**
88+
`Create Object P024 Invalid JSON`
89+
90+
- **Method:**
91+
`POST`
92+
93+
- **URL Path:**
94+
`/objects`
95+
96+
- **Headers:**
97+
98+
| Key | Value |
99+
| ------------ | ---------------- |
100+
| Content-Type | application/json |
101+
102+
You can **Add Header** as needed (e.g., Authorization, Custom-Token).
103+
104+
- **Request Body:**
105+
106+
````json
107+
{
108+
"name": "AUT Test Object P024",
109+
"data": {
110+
"key": "value"
111+
}
112+
}```
113+
````
114+
115+
### 💾 Actions
116+
117+
- ✅ **Save Changes** — Apply edits to the test step and update the suite.
118+
- ❌ **Cancel** — Discard any unsaved modifications and revert to the last saved state.

versioned_sidebars/version-2.0.0-sidebars.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,29 @@
228228
"collapsible": true,
229229
"collapsed": true,
230230
"items": [
231+
{
232+
"type": "doc",
233+
"label": "What is API testing?",
234+
"id": "running-keploy/about-api-testing"
235+
},
231236
{
232237
"type": "category",
233-
"label": "How ATG Works",
238+
"label": "How Keploy's ATG Works",
234239
"collapsible": true,
235240
"collapsed": true,
236241
"items": [
242+
"running-keploy/test-run-reports",
243+
"running-keploy/test-generate",
237244
"running-keploy/api-test-generator"
245+
238246
]
239-
}
247+
},
248+
249+
{
250+
"type": "doc",
251+
"label": "Best Practices for API Testing",
252+
"id": "running-keploy/best-practices-api-testing"
253+
}
240254
]
241255
}
242256
],

0 commit comments

Comments
 (0)