diff --git a/testing_api.go b/testing_api.go index 13093c1..52554f3 100644 --- a/testing_api.go +++ b/testing_api.go @@ -71,6 +71,22 @@ func (a *Api) AtPath(path string) *Api { } } +// RunSub 在单个接口测试 Func 内再分子场景,便于 go test -run 收窄。 +func (a *Api) RunSub(desc string, fn func(a *Api)) { + if a == nil || a.t == nil { + fn(a) + return + } + a.t.Run(desc, func(t *testing.T) { + fn(&Api{ + app: a.app, + path: a.path, + t: t, + session: a.session, + }) + }) +} + // JSON 设置 JSON body,返回 ApiCase 构建器 func (a *Api) JSON(body interface{}) *ApiCase { c := a.newCase()