mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
Merge pull request #82 from xucong053/main
fix: failed to generate API test report when data is null
This commit is contained in:
@@ -235,6 +235,7 @@
|
||||
<a class="close" href="#record_{{$suite_index}}_{{$loop_index}}">×</a>
|
||||
<div class="content">
|
||||
<h3>Name: {{ .Name }}</h3>
|
||||
{{- if .Data}}
|
||||
<h3>Request:</h3>
|
||||
<div style="overflow: auto">
|
||||
<table>
|
||||
@@ -332,8 +333,8 @@
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{{- end }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
33
runner.go
33
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user