feat(api): 添加备注功能以增强用例描述

- 在 Api 和 ApiCase 中新增 Note 方法,允许为用例设置可选备注
- 更新 TestRecord 结构体,包含备注字段以便记录用例信息
- 修改 Swagger 生成逻辑,支持备注字段的输出
- 更新文档,详细说明 Note 方法的使用及其在调试控制台的显示效果
This commit is contained in:
2026-03-15 11:45:21 +08:00
parent 71e415dfe1
commit 47e13b532b
4 changed files with 52 additions and 20 deletions
+15
View File
@@ -110,6 +110,13 @@ func (a *Api) Delete(desc string, status int, msg ...string) *ApiResponse {
return a.newCase().Delete(desc, status, msg...)
}
// Note 为下一条用例设置备注,返回可继续链式的 ApiCase
func (a *Api) Note(note string) *ApiCase {
c := a.newCase()
c.note = note
return c
}
// DB 获取数据库实例(在测试事务内)
func (a *Api) DB() *HoTimeDB {
return &a.app.Db
@@ -134,6 +141,7 @@ type ApiCase struct {
fileField string
fileName string
fileContent []byte
note string
}
// JSON 叠加 JSON body
@@ -180,6 +188,12 @@ func (c *ApiCase) WithSession(s Map) *ApiCase {
return c
}
// Note 为本条用例添加可选备注,备注将显示在 swagger 调试控制台
func (c *ApiCase) Note(note string) *ApiCase {
c.note = note
return c
}
// Get 终端操作:GET 请求 + 断言
func (c *ApiCase) Get(desc string, status int, msg ...string) *ApiResponse {
return c.execute("GET", desc, status, msg...)
@@ -247,6 +261,7 @@ func (c *ApiCase) execute(method, desc string, expectStatus int, expectMsg ...st
Passed: passed,
Duration: duration,
Method: method,
Note: c.note,
}
if c.query != nil {
record.Query = c.query