Skip to content

Commit

Permalink
Handle arbitrary number of sub suites in junit reports
Browse files Browse the repository at this point in the history
  • Loading branch information
William Petit committed Nov 21, 2019
1 parent 93e3ed9 commit ca25290
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/joshdk/go-junit

go 1.12

require github.com/stretchr/testify v1.4.0
require (
github.com/davecgh/go-spew v1.1.0
github.com/stretchr/testify v1.4.0
)
3 changes: 3 additions & 0 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func ingestSuite(root xmlNode) Suite {

for _, node := range root.Nodes {
switch node.XMLName.Local {
case "testsuite":
testsuite := ingestSuite(node)
suite.Suites = append(suite.Suites, testsuite)
case "testcase":
testcase := ingestTestcase(node)
suite.Tests = append(suite.Tests, testcase)
Expand Down
16 changes: 15 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package junit

import "time"
import (
"time"
)

// Status represents the result of a single a JUnit testcase. Indicates if a
// testcase was run, and if it was successful.
Expand Down Expand Up @@ -71,6 +73,9 @@ type Suite struct {
// Tests is an ordered collection of tests with associated results.
Tests []Test `json:"tests,omitempty" yaml:"tests,omitempty"`

// Suites is an ordered collection of suites with associated results.
Suites []Suite `json:"suites,omitempty" yaml:"suites,omitempty"`

// SystemOut is textual test output for the suite. Usually output that is
// written to stdout.
SystemOut string `json:"stdout,omitempty" yaml:"stdout,omitempty"`
Expand Down Expand Up @@ -101,6 +106,15 @@ func (s *Suite) Aggregate() {
}
}

for _, suite := range s.Suites {
suite.Aggregate()
totals.Duration += suite.Totals.Duration
totals.Passed += suite.Totals.Passed
totals.Skipped += suite.Totals.Skipped
totals.Failed += suite.Totals.Failed
totals.Error += suite.Totals.Error
}

s.Totals = totals
}

Expand Down

0 comments on commit ca25290

Please sign in to comment.