133 lines
2.6 KiB
Markdown
133 lines
2.6 KiB
Markdown
|
|
# 快速開始指南
|
|||
|
|
|
|||
|
|
## 🚀 最簡單的使用方式
|
|||
|
|
|
|||
|
|
### 1. 查看所有可用命令
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd test
|
|||
|
|
make help
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 運行冒煙測試(最常用)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 設置 API 地址
|
|||
|
|
export BASE_URL=https://api.example.com
|
|||
|
|
|
|||
|
|
# 運行所有冒煙測試
|
|||
|
|
make smoke
|
|||
|
|
|
|||
|
|
# 或運行單個測試
|
|||
|
|
make smoke-health
|
|||
|
|
make smoke-auth
|
|||
|
|
make smoke-user
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 3. 運行負載測試
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 設置 API 地址
|
|||
|
|
export BASE_URL=https://pre-api.example.com
|
|||
|
|
|
|||
|
|
# 運行負載測試
|
|||
|
|
make load
|
|||
|
|
make load-auth
|
|||
|
|
make load-user
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 4. 運行壓力測試
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 設置 API 地址
|
|||
|
|
export BASE_URL=https://pre-api.example.com
|
|||
|
|
|
|||
|
|
# 運行壓力測試
|
|||
|
|
make stress
|
|||
|
|
make stress-auth
|
|||
|
|
make stress-user
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 5. 運行生產環境測試
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 設置環境變數
|
|||
|
|
export BASE_URL=https://api.example.com
|
|||
|
|
export TEST_LOGIN_ID=test@example.com
|
|||
|
|
export TEST_PASSWORD=TestPassword123!
|
|||
|
|
|
|||
|
|
# 運行夜間測試
|
|||
|
|
make nightly
|
|||
|
|
make nightly-health
|
|||
|
|
make nightly-auth
|
|||
|
|
make nightly-user
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 📝 常用命令速查
|
|||
|
|
|
|||
|
|
| 命令 | 說明 |
|
|||
|
|
|------|------|
|
|||
|
|
| `make help` | 顯示所有可用命令 |
|
|||
|
|
| `make smoke` | 運行所有冒煙測試 |
|
|||
|
|
| `make load` | 運行所有負載測試 |
|
|||
|
|
| `make stress` | 運行所有壓力測試 |
|
|||
|
|
| `make nightly` | 運行所有夜間測試 |
|
|||
|
|
| `make run TEST=tests/smoke/smoke-auth-test.js` | 運行指定測試 |
|
|||
|
|
| `make clean` | 清理 Docker 資源 |
|
|||
|
|
|
|||
|
|
## 🔧 環境變數設置
|
|||
|
|
|
|||
|
|
### 方式 1: 使用 export(推薦)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
export BASE_URL=https://api.example.com
|
|||
|
|
export TEST_LOGIN_ID=test@example.com
|
|||
|
|
export TEST_PASSWORD=TestPassword123!
|
|||
|
|
make smoke
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 方式 2: 直接在命令中指定
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
make smoke BASE_URL=https://api.example.com
|
|||
|
|
make nightly BASE_URL=https://api.example.com TEST_LOGIN_ID=test@example.com TEST_PASSWORD=TestPassword123!
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 💡 提示
|
|||
|
|
|
|||
|
|
1. **首次使用**:不需要構建 Docker 映像,Makefile 會自動使用官方的 `grafana/k6:latest` 映像
|
|||
|
|
2. **本地運行**:如果本地已安裝 k6,可以使用 `make run-local TEST=...`
|
|||
|
|
3. **查看結果**:測試結果會直接輸出到終端,也可以使用 `make run-with-output` 保存到文件
|
|||
|
|
|
|||
|
|
## 🐛 常見問題
|
|||
|
|
|
|||
|
|
### Q: 如何運行自定義測試文件?
|
|||
|
|
|
|||
|
|
A: 使用 `make run` 命令:
|
|||
|
|
```bash
|
|||
|
|
make run TEST=tests/smoke/smoke-auth-test.js
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Q: 如何設置不同的 API 地址?
|
|||
|
|
|
|||
|
|
A: 使用環境變數:
|
|||
|
|
```bash
|
|||
|
|
export BASE_URL=https://dev-api.example.com
|
|||
|
|
make smoke
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Q: 如何查看測試結果?
|
|||
|
|
|
|||
|
|
A: 測試結果會直接輸出到終端。如果需要保存,使用:
|
|||
|
|
```bash
|
|||
|
|
make run-with-output TEST=tests/smoke/smoke-auth-test.js OUTPUT=results.json
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Q: 如何清理 Docker 資源?
|
|||
|
|
|
|||
|
|
A: 使用 `make clean` 命令:
|
|||
|
|
```bash
|
|||
|
|
make clean
|
|||
|
|
```
|
|||
|
|
|