性能测试 CodeArts PerfTest-签名约定:IResultV1接口实现
IResultV1接口实现
package mainimport ("fmt""time")const (InnerVarName = "__name"InnerVarGoroutineId = "__goroutine_id"InnerVarExecutorIndex = "__executor_index"InnerVarExecutorCount = "__executor_count")type IResultV1 interface {GetName() stringGetUrl() stringGetMethod() stringGetRequestHeader() map[string]stringGetRequestBody() stringGetSentBytes() intGetResponseCode() intGetResponseHeader() map[string]stringGetResponseBody() stringGetReceivedBytes() intGetFailureMessage() stringIsSuccess() boolGetBeginTime() int64GetEndTime() int64GetSubResults() []interface{}}//acquireResult generates root result.//just call one time on the main func and generate sub result using parent.addSub()func acquireResult(name string) *Result {result := &Result{}result.Name = nameresult.RequestHeader = map[string]string{}result.ResponseHeader = map[string]string{}result.ResponseCode = 200result.Success = trueresult.BeginTime = time.Now().UnixMilli()result.EndTime = time.Now().UnixMilli()return result}type Result struct {Name stringUrl stringMethod stringRequestHeader map[string]stringRequestBody stringSentBytes intResponseCode intResponseHeader map[string]stringResponseBody stringReceivedBytes intFailureMessage stringSuccess boolBeginTime int64EndTime int64SubResults []interface{}SubIndex int}func (r *Result) GetName() string {return r.Name}func (r *Result) GetUrl() string {return r.Url}func (r *Result) GetMethod() string {return r.Method}func (r *Result) GetRequestHeader() map[string]string {return r.RequestHeader}func (r *Result) GetRequestBody() string {return r.RequestBody}func (r *Result) GetSentBytes() int {return r.SentBytes}func (r *Result) GetResponseCode() int {return r.ResponseCode}func (r *Result) GetResponseHeader() map[string]string {return r.ResponseHeader}func (r *Result) GetResponseBody() string {return r.ResponseBody}func (r *Result) GetReceivedBytes() int {return r.ReceivedBytes}func (r *Result) GetFailureMessage() string {return r.FailureMessage}func (r *Result) IsSuccess() bool {return r.Success}func (r *Result) GetBeginTime() int64 {return r.BeginTime}func (r *Result) GetEndTime() int64 {return r.EndTime}func (r *Result) GetSubResults() []interface{} {return r.SubResults}//begin records begin time, do not forget call this function to updatefunc (r *Result) begin() {r.BeginTime = time.Now().UnixMilli()}//end records end time, do not forget call this function to updatefunc (r *Result) end() {r.EndTime = time.Now().UnixMilli()}//addSub adds sub result to parent, call this function adding sub result always.//if name is not empty, renaming will be disabledfunc (r *Result) addSub(name string) *Result {if name == "" {name = fmt.Sprintf("%s-%d", r.Name, r.SubIndex)r.SubIndex++} else {name = fmt.Sprintf("%s-%s", r.Name, name)}sub := acquireResult(name)r.SubResults = append(r.SubResults, sub)return sub}
名称 |
含义 |
补充说明 |
---|---|---|
Name |
请求名称 |
根result需使用内置参数__name设置。 |
Url |
请求地址 |
- |
Method |
方法 |
用于HTTP的POST,GET等。 |
RequestHeader |
请求头 |
用于HTTP。 |
RequestBody |
请求数据 |
建议不要记录请求较大的数据,例如上传文件,仅记录摘要即可。 |
SentBytes |
发送字节数 |
- |
ResponseCode |
响应码 |
记录响应状态,可以用于HTTP状态码或者自定义状态码,用于报告统计响应状态数量用于分析。 响应码范围:[100,599] |
ResponseHeader |
响应头 |
用于HTTP。 |
ResponseBody |
响应数据 |
建议不要记录响应较大的数据,例如下载文件,仅记录摘要即可。 |
ReceivedBytes |
接收字节数 |
- |
FailureMessage |
失败信息 |
- |
Success |
是否成功 |
- |
BeginTime |
请求开始时间 |
单位:毫秒 |
EndTime |
请求结束时间 |
单位:毫秒 |
SubResults |
子请求 |
当自定义请求需要多个子请求共同完成,需要使用该字段记录各个子请求执行情况。 |
SubIndex |
子请求索引 |
当使用父Result的addSub方法生成子Result时,如果不为子Result自定义名称,将使用该字段自增产生索引用于生成子Result名称。 |
- 性能测试使用流程_性能测试怎么样_性能测试 CodeArts PerfTest-华为云
- 什么是性能测试_性能测试作用_性能测试 CodeArts PerfTest-华为云
- 如何在测试计划服务中使用关键字?
- 性能测试产品优势_性能测试应用场景_性能测试CodeArts PerfTest-华为云
- 性能测试有哪些特性_性能测试特点_性能测试 CodeArts PerfTest-华为云
- 性能测试基本概念_性能测试有什么作用_性能测试 CodeArts PerfTest-华为云
- 华为云CodeArts API_接口迁移_接口导入
- 华为云CodeArts API_如何利用CodeArts API设计一个接口?
- 华为云CodeArts API_API测试_接口测试_关键字
- 性能测试使用教程_性能测试操作步骤_性能测试快速入门-华为云