mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-07-05 13:32:54 -05:00
Extract and report coverage information.
When `go test` is run on multiple packages and with coverage collection enabled, it appends coverage information to the final result line for each package. With this change, properly handle this additional information and add it into the JUnit XML report as a property of the test suite.
This commit is contained in:
@ -260,6 +260,73 @@ var testCases = []TestCase{
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "09-coverage.txt",
|
||||
reportName: "09-report.xml",
|
||||
report: &Report{
|
||||
Packages: []Package{
|
||||
{
|
||||
Name: "package/name",
|
||||
Time: 160,
|
||||
Tests: []*Test{
|
||||
{
|
||||
Name: "TestZ",
|
||||
Time: 60,
|
||||
Result: PASS,
|
||||
Output: []string{},
|
||||
},
|
||||
{
|
||||
Name: "TestA",
|
||||
Time: 100,
|
||||
Result: PASS,
|
||||
Output: []string{},
|
||||
},
|
||||
},
|
||||
CoveragePct: "13.37",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "10-multipkg-coverage.txt",
|
||||
reportName: "10-report.xml",
|
||||
report: &Report{
|
||||
Packages: []Package{
|
||||
{
|
||||
Name: "package1/foo",
|
||||
Time: 400,
|
||||
Tests: []*Test{
|
||||
{
|
||||
Name: "TestA",
|
||||
Time: 100,
|
||||
Result: PASS,
|
||||
Output: []string{},
|
||||
},
|
||||
{
|
||||
Name: "TestB",
|
||||
Time: 300,
|
||||
Result: PASS,
|
||||
Output: []string{},
|
||||
},
|
||||
},
|
||||
CoveragePct: "10.0",
|
||||
},
|
||||
{
|
||||
Name: "package2/bar",
|
||||
Time: 4200,
|
||||
Tests: []*Test{
|
||||
{
|
||||
Name: "TestC",
|
||||
Time: 4200,
|
||||
Result: PASS,
|
||||
Output: []string{},
|
||||
},
|
||||
},
|
||||
CoveragePct: "99.8",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestParser(t *testing.T) {
|
||||
@ -321,6 +388,9 @@ func TestParser(t *testing.T) {
|
||||
t.Errorf("Test.Output ==\n%s\n, want\n%s", testOutput, expTestOutput)
|
||||
}
|
||||
}
|
||||
if pkg.CoveragePct != expPkg.CoveragePct {
|
||||
t.Errorf("Package.CoveragePct == %s, want %s", pkg.CoveragePct, expPkg.CoveragePct)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user