go2xunit icon indicating copy to clipboard operation
go2xunit copied to clipboard

Support for nested test suite output ?

Open mohanraj-r opened this issue 7 years ago • 3 comments

I am using "github.com/tebeka/go2xunit/lib" to build junit xml output for a custom go tool. I am wondering if its possible to build nested test output e.g. as in xunit-viewer/complete_multi_suites.xml

e.g

 <!-- nested suites -->
        <testsuite name="parent">
            <testcase name="parent test"></testcase>
            <testsuite name="child one">
                <testcase name="child one test"></testcase>
            </testsuite>
            <testsuite name="child two">
                <testcase name="child two test"></testcase>
                <testsuite name="child of child two">
                    <testcase name="child of child two test"></testcase>
                </testsuite>
            </testsuite>
        </testsuite>

The basic usage of the lib in my tool is

suite := &xunit.Suite{Name: "foo"}

	for _, r := range results {
                 t := &xunit.Test{
				Name:   r.Name,
				Status:  r.Status,
				Message: r.GetDebugInfo(),
			}
			suite.Tests = append(suite.Tests, t)
        }

xunit.WriteXML(xunit.Suites{suite}, out, xunit.XUnitTemplate, time.Now())

But the results have 3 level nested hierarchy of data (not shown in the sample above for simplification) and distinctly different categories. I would like to use the nested structure of xunit testsuite to produce a better nested output than the plain single level output. But not sure if its possible using "go2xunit/lib"

For this to be possible I guess the Suite type should have a pointer to itself ? I see that the Test type has an unexported field isParentTest - I was able to trace out how this field is used vaguely - but not sure if this would be helpful here esp since its not exported.

mohanraj-r avatar May 14 '18 22:05 mohanraj-r

Hi. Will have a look Thursday.

tebeka avatar May 15 '18 05:05 tebeka

@tebeka wondering if you had a chance to look into this

mohanraj-r avatar May 17 '18 22:05 mohanraj-r

I guess it's possible and will require some code changes. Sadly I'm super busy right now and don't have time to do these changes. I'll probably have some free time mid-June.

I'd love to get a patch if you're interested, can mentor to some degree.

tebeka avatar May 19 '18 06:05 tebeka