From 724bb76ce1fa7a39b1eb68c2b80f9ae3f24cd8a5 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Fri, 11 Feb 2022 15:06:22 +0800 Subject: [PATCH 1/2] fix: failed to generate API test report when data is null. --- internal/report/template.html | 3 ++- runner.go | 33 ++++++++++++++++++--------------- runner_test.go | 13 +++++++++++++ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/internal/report/template.html b/internal/report/template.html index 978f2154..4bff6c65 100644 --- a/internal/report/template.html +++ b/internal/report/template.html @@ -235,6 +235,7 @@ ×

Name: {{ .Name }}

+ {{- if .Data}}

Request:

@@ -332,8 +333,8 @@
-
+ {{- end }} diff --git a/runner.go b/runner.go index 2d976c73..135dc2e2 100644 --- a/runner.go +++ b/runner.go @@ -225,23 +225,25 @@ func (r *caseRunner) run() error { r.startTime = time.Now() for index := range r.TestCase.TestSteps { - stepData, err := r.runStep(index, config) - if err != nil { - if r.hrpRunner.failfast { - return errors.Wrap(err, "abort running due to failfast setting") + stepDataObj, err := r.runStep(index, config) + if stepDataObj == nil { + stepDataObj = &stepData{ + Name: r.TestCase.TestSteps[index].Name(), + Success: false, } } - if stepData != nil { - if err != nil { - stepData.Attachment = err.Error() - } - r.summary.Records = append(r.summary.Records, stepData) - r.summary.Success = r.summary.Success && stepData.Success - r.summary.Stat.Total += 1 - if stepData.Success { - r.summary.Stat.Successes += 1 - } else { - r.summary.Stat.Failures += 1 + r.summary.Records = append(r.summary.Records, stepDataObj) + r.summary.Success = r.summary.Success && stepDataObj.Success + r.summary.Stat.Total += 1 + if stepDataObj.Success { + r.summary.Stat.Successes += 1 + } else { + r.summary.Stat.Failures += 1 + } + if err != nil { + stepDataObj.Attachment = err.Error() + if r.hrpRunner.failfast { + return errors.Wrap(err, "abort running due to failfast setting") } } } @@ -602,6 +604,7 @@ func (r *caseRunner) runStepRequest(step *TStep) (stepResult *stepData, err erro Proto: "HTTP/1.1", ProtoMajor: 1, ProtoMinor: 1, + Close: true, // prevent the connection from being re-used } // prepare request headers diff --git a/runner_test.go b/runner_test.go index 4b79dfc0..2a7fce74 100644 --- a/runner_test.go +++ b/runner_test.go @@ -123,6 +123,19 @@ func TestInitRendezvous(t *testing.T) { func TestGenHTMLReport(t *testing.T) { summary := newOutSummary() + caseSummary1 := newSummary() + caseSummary2 := newSummary() + stepResult1 := &stepData{} + stepResult2 := &stepData{ + Name: "Test", + StepType: stepTypeRequest, + Success: false, + ContentSize: 0, + Attachment: "err", + } + caseSummary1.Records = []*stepData{stepResult1, stepResult2, nil} + summary.appendCaseSummary(caseSummary1) + summary.appendCaseSummary(caseSummary2) err := genHTMLReport(summary) if err != nil { t.Error(err) From a3c60da51bfdf4505bfdc9294553a78f931d063e Mon Sep 17 00:00:00 2001 From: debugtalk Date: Fri, 11 Feb 2022 23:51:48 +0800 Subject: [PATCH 2/2] change: update survey --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 19d82ec7..81654d25 100644 --- a/README.md +++ b/README.md @@ -313,4 +313,4 @@ func TestCaseDemo(t *testing.T) { [examples]: https://github.com/httprunner/hrp/blob/main/examples/ [CHANGELOG]: docs/CHANGELOG.md [pushgateway]: https://github.com/prometheus/pushgateway -[survey]: https://wenjuan.feishu.cn/m?t=sVRvigY12Szi-gbbo +[survey]: https://wj.qq.com/s2/9699514/0d19/