Skip to content

feat: support skip skipped tests #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/gojunitreport/go-junit-report.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
Hostname string
PackageName string
SkipXMLHeader bool
SkipSkipped bool
SubtestMode gotest.SubtestMode
Properties map[string]string
TimestampFunc func() time.Time
Expand Down Expand Up @@ -71,7 +72,7 @@ func (c Config) Run(input io.Reader, output io.Writer) (*gtr.Report, error) {
}

func (c Config) writeJunitXML(w io.Writer, report gtr.Report) error {
testsuites := junit.CreateFromReport(report, c.Hostname)
testsuites := junit.CreateFromReport(report, c.Hostname, c.SkipSkipped)
if !c.SkipXMLHeader {
_, err := fmt.Fprintf(w, xml.Header)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions junit/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type Output struct {
}

// CreateFromReport creates a JUnit representation of the given gtr.Report.
func CreateFromReport(report gtr.Report, hostname string) Testsuites {
func CreateFromReport(report gtr.Report, hostname string, skipSkipped bool) Testsuites {
var suites Testsuites
for _, pkg := range report.Packages {
var duration time.Duration
Expand All @@ -172,8 +172,10 @@ func CreateFromReport(report gtr.Report, hostname string) Testsuites {
}

for _, test := range pkg.Tests {
duration += test.Duration
suite.AddTestcase(createTestcaseForTest(pkg.Name, test))
if !(test.Result == gtr.Skip && skipSkipped) {
duration += test.Duration
suite.AddTestcase(createTestcaseForTest(pkg.Name, test))
}
}

// JUnit doesn't have a good way of dealing with build or runtime
Expand Down
93 changes: 90 additions & 3 deletions junit/junit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,94 @@ func TestCreateFromReport(t *testing.T) {
},
}

got := CreateFromReport(report, "")
got := CreateFromReport(report, "", false)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("CreateFromReport incorrect, diff (-want, +got):\n%s\n", diff)
}
}

func TestCreateFromReportWithSkipped(t *testing.T) {
report := gtr.Report{
Packages: []gtr.Package{
{
Name: "package/name",
Timestamp: time.Date(2022, 6, 26, 0, 0, 0, 0, time.UTC),
Duration: 1 * time.Second,
Coverage: 0.9,
Output: []string{"output"},
Properties: []gtr.Property{{Name: "go.version", Value: "go1.18"}},
Tests: []gtr.Test{
{
Name: "TestPass",
Result: gtr.Pass,
Output: []string{"ok"},
},
{
Name: "TestFail",
Result: gtr.Fail,
Output: []string{"fail"},
},
{
Name: "TestSkip",
Result: gtr.Skip,
},
},
BuildError: gtr.Error{Name: "Build error"},
RunError: gtr.Error{Name: "Run error"},
},
},
}

want := Testsuites{
Tests: 4,
Errors: 2,
Failures: 1,
Skipped: 0,
Suites: []Testsuite{
{
Name: "package/name",
Tests: 4,
Errors: 2,
ID: 0,
Failures: 1,
Skipped: 0,
Time: "1.000",
Timestamp: "2022-06-26T00:00:00Z",
Properties: &[]Property{
{Name: "go.version", Value: "go1.18"},
{Name: "coverage.statements.pct", Value: "0.90"},
},
Testcases: []Testcase{
{
Name: "TestPass",
Classname: "package/name",
Time: "0.000",
SystemOut: &Output{Data: "ok"},
},
{
Name: "TestFail",
Classname: "package/name",
Time: "0.000",
Failure: &Result{Message: "Failed", Data: "fail"},
},
{
Classname: "Build error",
Time: "0.000",
Error: &Result{Message: "Build error"},
},
{
Name: "Failure",
Classname: "Run error",
Time: "0.000",
Error: &Result{Message: "Runtime error"},
},
},
SystemOut: &Output{Data: "output"},
},
},
}

got := CreateFromReport(report, "", true)
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("CreateFromReport incorrect, diff (-want, +got):\n%s\n", diff)
}
Expand Down Expand Up @@ -193,8 +280,8 @@ func TestWriteXML(t *testing.T) {

var suites Testsuites

ts := Testsuite{Name:"Example"}
ts.AddTestcase(Testcase{Name: "Test", })
ts := Testsuite{Name: "Example"}
ts.AddTestcase(Testcase{Name: "Test"})
suites.AddSuite(ts)

var buf bytes.Buffer
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
properties = make(keyValueFlag)
parser = flag.String("parser", "gotest", "set input parser: gotest, gojson")
mode = flag.String("subtest-mode", "", "set subtest `mode`: ignore-parent-results (subtest parents always pass), exclude-parents (subtest parents are excluded from the report)")
skipSkipped = flag.Bool("skip-skipped-tests", false, "do not consider skipped tests")

// debug flags
printEvents = flag.Bool("debug.print-events", false, "print events generated by the go test parser")
Expand Down Expand Up @@ -103,6 +104,7 @@ func main() {
Parser: *parser,
Hostname: hostname,
PackageName: *packageName,
SkipSkipped: *skipSkipped,
SkipXMLHeader: *noXMLHeader,
SubtestMode: subtestMode,
Properties: properties,
Expand Down