junitxml

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 4 Imported by: 1

README

JUnit XML

This project provides a library and command line tool to process junit xml files.

The supported XML format is based on the testmoapp/junitxml project which documents the common use of JUnit-style XML files by testing and ci tools.

Installation

For the library, use:

go get go.cluttr.dev/junitxml@latest

For the command line tool, use:

go install go.cluttr.dev/junitxml/cmd/junitxml@latest

Usage

Library

For library usage, see the package docs or the following quick-start example:

package main

import (
    "fmt"
    "log"
    "os"

    "go.cluttr.dev/junitxml"
)

func main() {
    file, err := os.Open("junit.xml")
    if err := nil {
        log.Fatal("error opening file: %v", err)
    }
    defer file.Close()

    report, err := junitxml.Parse(file)
    if err != nil {
        log.Fatal("error parsing file: %v", err)
    }

    fmt.Printf("Test execution took %v seconds.\n", report.time)
}
Command line tool

To see what the cli can do, run:

$ junitxml -h
Process junit xml files.

USAGE
  junitxml [COMMAND] [OPTION]... [ARG]...

COMMANDS
  merge    Merge junit xml files
  version  Show version information

Documentation

Index

Constants

View Source
const (
	AttachmentRegex = `\[\[ATTACHMENT\|(?<path>[^\[\]\|]+?)\]\]`
	PropertyRegex   = `\[\[PROPERTY\|(?<name>[^\[\]\|=]+)=(?<value>[^\[\]\|=]+)\]\]`
)

Variables

This section is empty.

Functions

func ParseTextAttachments

func ParseTextAttachments(s string) []string

Types

type Error

type Error struct {
	// XMLName xml.Name `xml:"error"`
	Message string `xml:"message,attr,omitempty"`
	Type    string `xml:"type,attr,omitempty"`
	Text    string `xml:",innerxml"`
}

type Failure

type Failure struct {
	// XMLName xml.Name `xml:"failure"`
	Message string `xml:"message,attr,omitempty"`
	Type    string `xml:"type,attr,omitempty"`
	Text    string `xml:",innerxml"`
}

type Property

type Property struct {
	// XMLName xml.Name `xml:"property"`
	Name  string `xml:"name,attr,omitempty"`
	Value string `xml:"value,attr,omitempty"`
	Text  string `xml:",innerxml"`
}

func ParseTextProperties

func ParseTextProperties(s string) []Property

type Skipped

type Skipped struct {
	// XMLName xml.Name `xml:"skipped"`
	Message string `xml:"message,attr,omitempty"`
}

type SystemErr

type SystemErr struct {
	// XMLName xml.Name `xml:"system-err"`
	Text string `xml:",innerxml"`
}

type SystemOut

type SystemOut struct {
	// XMLName xml.Name `xml:"system-out"`
	Text string `xml:",innerxml"`
}

type TestCase

type TestCase struct {
	// XMLName   xml.Name  `xml:"testcase"`
	Name       string     `xml:"name,attr,omitempty"`
	Classname  string     `xml:"classname,attr,omitempty"`
	Tests      int        `xml:"tests,attr,omitempty"`
	Time       float64    `xml:"time,attr,omitempty"`
	File       string     `xml:"file,attr,omitempty"`
	Line       int        `xml:"line,attr,omitempty"`
	Failure    *Failure   `xml:"failure"`
	Error      *Error     `xml:"error"`
	Skipped    *Skipped   `xml:"skipped"`
	Properties []Property `xml:"properties>property,omitempty"`
	SystemOut  *SystemOut `xml:"system-out"`
	SystemErr  *SystemErr `xml:"system-err"`
}

type TestReport

type TestReport struct {
	XMLName    xml.Name    `xml:"testsuites"`
	Tests      int         `xml:"tests,attr,omitempty"`
	Failures   int         `xml:"failures,attr,omitempty"`
	Errors     int         `xml:"errors,attr,omitempty"`
	Skipped    int         `xml:"skipped,attr,omitempty"`
	Time       float64     `xml:"time,attr,omitempty"`
	Timestamp  string      `xml:"timestamp,attr,omitempty"`
	TestSuites []TestSuite `xml:"testsuite"`
}

func Merge

func Merge(reports []TestReport) TestReport

Merge combines multiple TestReport items into one. The timestamp of final report will be left empty.

func Parse

func Parse(r io.Reader) (TestReport, error)

Parse reads XML-encoded data from the given reader and decodes it into a TestReport struct.

func ParseMany

func ParseMany(r io.Reader) ([]TestReport, error)

ParseMany works like Parse but supports reading multiple <testsuites> root elements and returns a TestReport for each of them.

type TestSuite

type TestSuite struct {
	// XMLName    xml.Name   `xml:"testsuite"`
	Name       string     `xml:"name,attr,omitempty"`
	Tests      int        `xml:"tests,attr,omitempty"`
	Failures   int        `xml:"failures,attr,omitempty"`
	Errors     int        `xml:"errors,attr,omitempty"`
	Skipped    int        `xml:"skipped,attr,omitempty"`
	Time       float64    `xml:"time,attr,omitempty"`
	Timestamp  string     `xml:"timestamp,attr,omitempty"`
	File       string     `xml:"file,attr,omitempty"`
	Properties []Property `xml:"properties>property,omitempty"`
	SystemOut  *SystemOut `xml:"system-out"`
	SystemErr  *SystemErr `xml:"system-err"`
	TestCases  []TestCase `xml:"testcase"`
}

Directories

Path Synopsis
cmd
junitxml command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL