I am programmatically calling go test
to run tests.
func executeAllTests(c *gin.Context) {
// Enable verbose
flag.Set("test.v", "true")
id := "myUniqueId"
// Asynchronously run the tests.
go runTestsAndWriteReport(id)
// Return
c.JSON(200, id)
}
func runTestsAndWriteReport(fileName string) {
testing.Main(
nil,
[]testing.InternalTest{
{"TestX", myTestPkg.TestX},
{"TestY", myTestPkg.TestY}
},
nil, nil,
)
// TODO: write output as JUnit XML to file "fileName"
}
I would like to write the test output in JUnit XML form to a file. There are frameworks, for example, gotestsum that can do this from the command line, however, I want to do it programmatically as shown above.
Any suggestion on how this can be done?