< Summary - Neospec Coverage

Information
Line coverage
100%
Covered lines: 44
Uncovered lines: 0
Coverable lines: 44
Total lines: 109
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Write0%00100%

File(s)

/home/runner/work/neospec/neospec/internal/adapters/reporter/junit.go

#LineLine coverage
 1package reporter
 2
 3import (
 4  "context"
 5  "encoding/xml"
 6  "fmt"
 7  "io"
 8  "time"
 9
 10  "github.com/jedi-knights/neospec/internal/domain"
 11)
 12
 13// JUnit writes test results in JUnit XML format.
 14// https://github.com/testmoapp/junitxml
 15// Coverage data is not included — JUnit is a test-results-only format.
 16type JUnit struct{}
 17
 18// NewJUnit creates a JUnit reporter.
 19func NewJUnit() *JUnit { return &JUnit{} }
 20
 21type junitTestSuites struct {
 22  XMLName    xml.Name         `xml:"testsuites"`
 23  Tests      int              `xml:"tests,attr"`
 24  Failures   int              `xml:"failures,attr"`
 25  Errors     int              `xml:"errors,attr"`
 26  Skipped    int              `xml:"skipped,attr"`
 27  Time       float64          `xml:"time,attr"`
 28  Timestamp  string           `xml:"timestamp,attr"`
 29  TestSuites []junitTestSuite `xml:"testsuite"`
 30}
 31
 32type junitTestSuite struct {
 33  Name      string          `xml:"name,attr"`
 34  Tests     int             `xml:"tests,attr"`
 35  Failures  int             `xml:"failures,attr"`
 36  Errors    int             `xml:"errors,attr"`
 37  Skipped   int             `xml:"skipped,attr"`
 38  Time      float64         `xml:"time,attr"`
 39  TestCases []junitTestCase `xml:"testcase"`
 40}
 41
 42type junitTestCase struct {
 43  Name    string        `xml:"name,attr"`
 44  Time    float64       `xml:"time,attr"`
 45  Failure *junitFailure `xml:"failure,omitempty"`
 46  Error   *junitError   `xml:"error,omitempty"`
 47  Skipped *junitSkipped `xml:"skipped,omitempty"`
 48}
 49
 50type junitFailure struct {
 51  Message string `xml:"message,attr"`
 52  Text    string `xml:",chardata"`
 53}
 54
 55type junitError struct {
 56  Message string `xml:"message,attr"`
 57  Text    string `xml:",chardata"`
 58}
 59
 60type junitSkipped struct{}
 61
 362func (j *JUnit) Write(_ context.Context, w io.Writer, suite *domain.SuiteResult, _ *domain.CoverageData) error {
 363  pass, fail, skip, errors := suite.Counts()
 364
 365  jSuite := junitTestSuite{
 366    Name:     "neospec",
 367    Tests:    len(suite.Tests),
 368    Failures: fail,
 369    Errors:   errors,
 370    Skipped:  skip,
 371    Time:     suite.Duration.Seconds(),
 372  }
 373
 374  for _, t := range suite.Tests {
 475    tc := junitTestCase{
 476      Name: t.Name,
 477      Time: t.Duration.Seconds(),
 478    }
 479    switch t.Status {
 180    case domain.StatusFail:
 181      tc.Failure = &junitFailure{Message: t.Error, Text: t.Error}
 182    case domain.StatusError:
 183      tc.Error = &junitError{Message: t.Error, Text: t.Error}
 184    case domain.StatusSkip:
 185      tc.Skipped = &junitSkipped{}
 86    }
 487    jSuite.TestCases = append(jSuite.TestCases, tc)
 88  }
 89
 390  root := junitTestSuites{
 391    Tests:      len(suite.Tests),
 392    Failures:   fail,
 393    Errors:     errors,
 394    Skipped:    skip,
 395    Time:       suite.Duration.Seconds(),
 396    Timestamp:  time.Now().UTC().Format(time.RFC3339),
 397    TestSuites: []junitTestSuite{jSuite},
 398  }
 399
 3100  _ = pass // pass count is not a JUnit attribute at the suites level
 3101
 3102  fmt.Fprintln(w, `<?xml version="1.0" encoding="UTF-8"?>`)
 3103  enc := xml.NewEncoder(w)
 3104  enc.Indent("", "  ")
 1105  if err := enc.Encode(root); err != nil {
 1106    return fmt.Errorf("encoding junit XML: %w", err)
 1107  }
 2108  return enc.Flush()
 109}

Methods/Properties

Write