Skip to content

Commit

Permalink
Save properties of a test case (joshdk#21)
Browse files Browse the repository at this point in the history
Some reporters use them to store additional information like file location
  • Loading branch information
fkorotkov authored and joshdk committed Apr 28, 2019
1 parent 6ce6523 commit ad7e11a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ func ingestProperties(root xmlNode) map[string]string {

func ingestTestcase(root xmlNode) Test {
test := Test{
Name: root.Attr("name"),
Classname: root.Attr("classname"),
Duration: duration(root.Attr("time")),
Status: StatusPassed,
Name: root.Attr("name"),
Classname: root.Attr("classname"),
Duration: duration(root.Attr("time")),
Status: StatusPassed,
Properties: root.Attrs,
}

for _, node := range root.Nodes {
Expand Down
54 changes: 54 additions & 0 deletions ingest_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright Josh Komoroske. All rights reserved.
// Use of this source code is governed by the MIT license,
// a copy of which can be found in the LICENSE.txt file.

package junit

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
)

func TestInjest(t *testing.T) {
tests := []struct {
title string
input []byte
expected []Suite
}{
{
title: "xml input",
input: []byte(`<testsuite errors="0" failures="1" file="Foo.java"><testcase name="unit tests" file="Foo.java"/></testsuite>`),
expected: []Suite{
{
Tests: []Test{
{
Name: "unit tests",
Status: "passed",
Properties: map[string]string{
"file": "Foo.java",
"name": "unit tests",
},
},
},
Totals: Totals{
Tests: 1,
Passed: 1,
},
},
},
},
}

for index, test := range tests {
name := fmt.Sprintf("#%d - %s", index+1, test.title)

t.Run(name, func(t *testing.T) {
actual, err := Ingest(test.input)
require.Nil(t, err)
require.NotEmpty(t, actual)
require.Equal(t, test.expected, actual)
})
}
}
4 changes: 4 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ type Test struct {
// Error == nil && (Status == Passed || Status == Skipped)
// Error != nil && (Status == Failed || Status == Error)
Error error `json:"error" yaml:"error"`

// Additional properties from XML node attributes.
// Some tools use them to store additional information about test location.
Properties map[string]string `json:"properties" yaml:"properties"`
}

// Error represents an erroneous test result.
Expand Down

0 comments on commit ad7e11a

Please sign in to comment.