Esempio n. 1
0
	testSuite *api.TestSuite
	report    *api.Report
	t         *template.Template
)

func TestApi(t *testing.T) {
	RegisterFailHandler(Fail)
	junitReporter := reporters.NewJUnitReporter("junit.xml")
	RunSpecsWithDefaultAndCustomReporters(t, "api Suite", []Reporter{junitReporter})
}

var _ = BeforeSuite(func() {
	testSuiteTmp, err := api.ParseJunitXML("sample_junit.xml")
	testSuite = testSuiteTmp
	Expect(err).Should(BeNil())

	report = api.Aggregate(testSuite)

	fmap := template.FuncMap{
		"formateFloatStr": api.FormateFloatStr,
		"isOdd":           api.IsOdd,
		"resultSymbol":    api.ResultSymbol,
	}

	t = template.New("test").Funcs(fmap)
	t = template.Must(t.ParseFiles("../../tmpl/summary.html"))
	t = template.Must(t.ParseFiles("../../tmpl/packages.html"))
	t = template.Must(t.ParseFiles("../../tmpl/testcase.html"))
	t = template.Must(t.ParseFiles("../../tmpl/failure_detail.html"))
})
Esempio n. 2
0
func main() {
	flag.Parse()
	if junitXmlPath == "" {
		fmt.Printf("No junit.xml path is provided.\n")
		return
	}

	junitXmlPath, err := filepath.Abs(junitXmlPath)
	if err != nil {
		fmt.Printf("No valid junit.xml path is provided: %s.\n", err.Error())
		return
	}

	if outputPath == "" {
		fmt.Printf("No output path instructed. Use current dir as default.")
		_outputPath, _err := os.Getwd()
		if _err != nil {
			fmt.Printf("No valid output dir is provided: %s.\n", err.Error())
			return
		}
		outputPath = _outputPath
	}

	if _, err = os.Stat(outputPath); os.IsNotExist(err) {
		err = genDir(outputPath)
		if err != nil {
			fmt.Printf("No valid output dir is provided: %s.\n", err.Error())
			return
		}
	} else if stat, _err := os.Stat(outputPath); _err != nil || stat.Mode().IsRegular() {
		fmt.Printf("Output path should be a directory.\n")
		return
	}

	fmt.Printf("Search with pattern %s .\n", junitXmlPath)
	matches, err := filepath.Glob(junitXmlPath)
	if err != nil {
		fmt.Printf("No valid junit.xml path is provided: %s.\n", err.Error())
		return
	}

	fmt.Printf("Filter out files: %v.\n", matches)

	t := api.Template()

	for _, f := range matches {
		if !strings.HasSuffix(f, ".xml") {
			continue
		}

		fmt.Printf("Start working on file %s .\n", f)

		testSuite, err := api.ParseJunitXML(f)
		if err != nil {
			fmt.Println("err : " + err.Error())
			continue
		}

		report := api.Aggregate(testSuite)

		out, err := genFileUnderDir(outputPath, f)
		if err != nil {
			fmt.Printf("Fail to create output file for junit xml %s cause err: %s\n", f, err.Error())
			continue
		}
		defer out.Close()

		err = api.ApplyTemplate(t, out, report)
		if err != nil {
			fmt.Printf("Fail to generate junit html report: %s .\n", err.Error())
		} else {
			fmt.Printf("Succeed to generate junit html report: %s .\n", out.Name())
		}
	}
}