-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from naodeng/main
add dataDriving demo and multiEnv demo
- Loading branch information
Showing
15 changed files
with
232 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Test config file for dev environment | ||
module.exports = { | ||
host: 'https://jsonplaceholder.typicode.com', // Test endpoint | ||
getAPI: '/posts/1', // Test GET API URL | ||
postAPI: '/posts', // Test POST API URL | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Test config file for test environment | ||
module.exports = { | ||
host: 'https://jsonplaceholder.typicode.com', // Test endpoint | ||
getAPI: '/posts/1', // Test GET API URL | ||
postAPI: '/posts', // Test POST API URL | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Test config file | ||
module.exports = { | ||
host: 'https://jsonplaceholder.typicode.com', // Test endpoint | ||
getAPI: '/posts/1', // Test GET API URL | ||
postAPI: '/posts', // Test POST API URL | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,55 @@ | ||
<div align="right"><strong>🇨🇳中文</a></strong> | <strong><a href="./README_EN.md">🇬🇧English</strong></div> | ||
<div align="right"><strong><a href="README_ZH.md">🇨🇳中文</a></strong> | <strong>🇬🇧English</strong></div> | ||
|
||
# SuperTest-Jest-demo | ||
a SuperTest API automation testing demo project with Jest | ||
|
||
一个使用 Jest 的 SuperTest API 自动化测试演示项目 | ||
## Environment preparation | ||
- Nodejs, I'm using v21.1.0. | ||
- SuperTest, I'm using version 6.3.3. | ||
- Jest, I'm using the latest version 29.7.0. | ||
|
||
## 环境准备 | ||
- Nodejs ,我使用的 v21.1.0 | ||
- SuperTest 我使用的 6.3.3 版本 | ||
- Jest 我使用的是最新的 29.7.0 版本 | ||
|
||
## 技术栈 | ||
## Tech stack | ||
- SuperTest | ||
- Jest | ||
- jest-html-reporters | ||
- GitHub action | ||
|
||
## 项目结构 | ||
## Project structure | ||
|
||
```Text | ||
SuperTest-Jest-demo | ||
├── README.md | ||
├── package.json | ||
├── package-lock.json | ||
├── Config // 测试配置文件 | ||
├── Config // TEST configuration file | ||
│ └── config.js | ||
├── Specs // 测试用例文件 | ||
├── Config // TEST data file | ||
│ └── requestData.js | ||
│ └── responseData.js | ||
├── Specs // TEST case file | ||
│ └── test.spec.js | ||
├── Utils // 测试工具文件 | ||
├── Utils // TEST tool file | ||
│ └── utils.js | ||
├── Report // 测试报告文件 | ||
├── Report // TEST report file | ||
│ └── report.html | ||
├── .gitignore | ||
└── node_modules // 项目依赖 | ||
└── node_modules // Project dependencies | ||
``` | ||
|
||
## 项目运行 | ||
## HOW TO RUN | ||
|
||
```bash | ||
node run test | ||
``` | ||
## 测试报告截图 | ||
## Test report screenshot | ||
|
||
![12ZreT](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/12ZreT.png) | ||
|
||
## 添加API测试用例 | ||
## Add API test cases | ||
|
||
- Just add a new test case in the Specs directory. | ||
|
||
- 在 Specs目录下新加测试用例即可 | ||
## More info | ||
|
||
## 更多信息 | ||
- [Project Tutorial](https://github.com/Automation-Test-Starter/SuperTest-API-Test-Starter) | ||
|
||
- [项目教程](https://github.com/Automation-Test-Starter/SuperTest-API-Test-Starter) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<div align="right"><strong>🇨🇳中文</a></strong> | <strong><a href="README.md">🇬🇧English</strong></div> | ||
|
||
# SuperTest-Jest-demo | ||
|
||
一个使用 Jest 的 SuperTest API 自动化测试演示项目 | ||
|
||
## 环境准备 | ||
- Nodejs ,我使用的 v21.1.0 | ||
- SuperTest 我使用的 6.3.3 版本 | ||
- Jest 我使用的是最新的 29.7.0 版本 | ||
|
||
## 技术栈 | ||
- SuperTest | ||
- Jest | ||
- jest-html-reporters | ||
- GitHub action | ||
|
||
## 项目结构 | ||
|
||
```Text | ||
SuperTest-Jest-demo | ||
├── README.md | ||
├── package.json | ||
├── package-lock.json | ||
├── Config // 测试配置文件 | ||
│ └── config.js | ||
├── Config // 测试数据文件 | ||
│ └── requestData.js | ||
│ └── responseData.js | ||
├── Specs // 测试用例文件 | ||
│ └── test.spec.js | ||
├── Utils // 测试工具文件 | ||
│ └── utils.js | ||
├── Report // 测试报告文件 | ||
│ └── report.html | ||
├── .gitignore | ||
└── node_modules // 项目依赖 | ||
``` | ||
|
||
## 项目运行 | ||
|
||
```bash | ||
node run test | ||
``` | ||
## 测试报告截图 | ||
|
||
![12ZreT](https://cdn.jsdelivr.net/gh/naodeng/blogimg@master/uPic/12ZreT.png) | ||
|
||
## 添加API测试用例 | ||
|
||
- 在 Specs目录下新加测试用例即可 | ||
|
||
## 更多信息 | ||
|
||
- [项目教程](https://github.com/Automation-Test-Starter/SuperTest-API-Test-Starter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Test: dataDrivingTest.spec.js | ||
const request = require('supertest'); | ||
|
||
const config = require('../Config/testConfig'); // import test config | ||
const requestData = require('../TestData/requestData'); // import request data | ||
const responseData = require('../TestData/responseData'); // import response data | ||
|
||
// Test Suite | ||
describe('Data Driving-Verify that the Get and POST API returns correctly', () => { | ||
// Test case 1 | ||
it('Data Driving-Verify that the GET API returns correctly', async () => { | ||
const res = await request(config.host) // Test endpoint | ||
.get(config.getAPI) // API endpoint | ||
.send(requestData.getAPI) // request body | ||
.expect(200); // use supertest's expect to verify that the status code is 200 | ||
// user jest's expect to verify the response body | ||
expect(res.status).toBe(200); // Verify that the status code is 200 | ||
expect(res.body).toEqual(responseData.getAPI); // Verify that the id is 1 | ||
}); | ||
|
||
// Test case 2 | ||
it('Data Driving-Verify that the POST API returns correctly', async() =>{ | ||
const res = await request(config.host) // Test endpoint | ||
.post(config.postAPI) // API endpoint | ||
.send(requestData.postAPI) // request body | ||
.expect(201); // use supertest's expect to verify that the status code is 201 | ||
// user jest's expect to verify the response body | ||
expect(res.statusCode).toBe(201); | ||
expect(res.body).toEqual(responseData.postAPI); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Test: multiEnvTest.spec.js | ||
const request = require('supertest'); | ||
|
||
const config = process.env.NODE_ENV === 'test' ? require('../Config/testConfig-test') : require('../Config/testConfig-dev'); // import test config | ||
const requestData = process.env.NODE_ENV === 'test' ? require('../TestData/requestData-test') : require('../TestData/requestData-dev'); // import request data | ||
const responseData= process.env.NODE_ENV === 'test' ? require('../TestData/responseData-test') : require('../TestData/responseData-dev'); // import response data | ||
|
||
// Test Suite | ||
describe('multiEnv-Verify that the Get and POST API returns correctly', () => { | ||
// Test case 1 | ||
it('multiEnv-Verify that the GET API returns correctly', async () => { | ||
const res = await request(config.host) // Test endpoint | ||
.get(config.getAPI) // API endpoint | ||
.send(requestData.getAPI) // request body | ||
.expect(200); // use supertest's expect to verify that the status code is 200 | ||
// user jest's expect to verify the response body | ||
expect(res.status).toBe(200); // Verify that the status code is 200 | ||
expect(res.body).toEqual(responseData.getAPI); // Verify that the id is 1 | ||
}); | ||
|
||
// Test case 2 | ||
it('multiEnv-Verify that the POST API returns correctly', async() =>{ | ||
const res = await request(config.host) // Test endpoint | ||
.post(config.postAPI) // API endpoint | ||
.send(requestData.postAPI) // request body | ||
.expect(201); // use supertest's expect to verify that the status code is 201 | ||
// user jest's expect to verify the response body | ||
expect(res.statusCode).toBe(201); | ||
expect(res.body).toEqual(responseData.postAPI); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Test request data file for dev environment | ||
module.exports = { | ||
getAPI: '', // request data for GET API | ||
postAPI:{ | ||
"title": "foo", | ||
"body": "bar", | ||
"userId": 1 | ||
}, // request data for POST API | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Test request data file for dev environment | ||
module.exports = { | ||
getAPI: '', // request data for GET API | ||
postAPI:{ | ||
"title": "foo", | ||
"body": "bar", | ||
"userId": 1 | ||
}, // request data for POST API | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Test request data file | ||
module.exports = { | ||
getAPI: '', // request data for GET API | ||
postAPI:{ | ||
"title": "foo", | ||
"body": "bar", | ||
"userId": 1 | ||
}, // request data for POST API | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Test response data file for dev environment | ||
module.exports = { | ||
getAPI: { | ||
"userId": 1, | ||
"id": 1, | ||
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", | ||
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" | ||
}, // response data for GET API | ||
postAPI:{ | ||
"title": "foo", | ||
"body": "bar", | ||
"userId": 1, | ||
"id": 101 | ||
}, // response data for POST API | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Test response data file for dev environment | ||
module.exports = { | ||
getAPI: { | ||
"userId": 1, | ||
"id": 1, | ||
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", | ||
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" | ||
}, // response data for GET API | ||
postAPI:{ | ||
"title": "foo", | ||
"body": "bar", | ||
"userId": 1, | ||
"id": 101 | ||
}, // response data for POST API | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Test response data file | ||
module.exports = { | ||
getAPI: { | ||
"userId": 1, | ||
"id": 1, | ||
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", | ||
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" | ||
}, // response data for GET API | ||
postAPI:{ | ||
"title": "foo", | ||
"body": "bar", | ||
"userId": 1, | ||
"id": 101 | ||
}, // response data for POST API | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters