From e3aa9fe33a8e7c042e1edbab36b16c689d6d98cc Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Tue, 5 Jan 2021 10:56:12 +0800 Subject: [PATCH] support cyrpress test framework --- src/model/testing.go | 38 +++++++++++++++++++++ src/service/testing/unitTestResult.go | 48 ++++++++++++++++++++++++++- src/utils/const/const.go | 11 +++--- src/ztf.go | 4 +-- 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/model/testing.go b/src/model/testing.go index e2fa2e96..6ea53e74 100644 --- a/src/model/testing.go +++ b/src/model/testing.go @@ -405,3 +405,41 @@ type RobotStatus struct { StartTime string `xml:"starttime,attr"` EndTime string `xml:"endtime,attr"` } + +// cypress +var CypressResults = "results" + +type CypressTestsuites struct { + XMLName xml.Name `xml:"testsuites"` + Text string `xml:",chardata"` + Name string `xml:"name,attr"` + Time string `xml:"time,attr"` + Tests string `xml:"tests,attr"` + Failures string `xml:"failures,attr"` + Testsuites []CypressTestsuite `xml:"testsuite"` +} + +type CypressTestsuite struct { + Text string `xml:",chardata"` + Name string `xml:"name,attr"` + Timestamp string `xml:"timestamp,attr"` + Tests string `xml:"tests,attr"` + File string `xml:"file,attr"` + Time float64 `xml:"time,attr"` + Failures string `xml:"failures,attr"` + Testcases []CypressTestcase `xml:"testcase"` +} + +type CypressTestcase struct { + Text string `xml:",chardata"` + Name string `xml:"name,attr"` + Time float64 `xml:"time,attr"` + Classname string `xml:"classname,attr"` + Failures []CypressFailure `xml:"failure"` +} + +type CypressFailure struct { + Text string `xml:",chardata"` + Message string `xml:"message,attr"` + Type string `xml:"type,attr"` +} diff --git a/src/service/testing/unitTestResult.go b/src/service/testing/unitTestResult.go index 31def11f..f276493b 100644 --- a/src/service/testing/unitTestResult.go +++ b/src/service/testing/unitTestResult.go @@ -22,7 +22,7 @@ func RetrieveUnitResult() (suites []model.UnitTestSuite, resultDir string) { resultDir = fmt.Sprintf("target%ssurefire-reports%s", constant.PthSep, constant.PthSep) } else if vari.UnitTestType == constant.UnitTestTypeTestNG && vari.UnitTestTool == constant.UnitTestToolMvn { resultDir = fmt.Sprintf("target%ssurefire-reports%sjunitreports", constant.PthSep, constant.PthSep) - } else if vari.UnitTestType == constant.UnitTestTypeRobot { + } else if vari.UnitTestType == constant.UnitTestTypeRobot || vari.UnitTestType == constant.UnitTestTypeCypress { resultDir = vari.UnitTestResults } else { resultDir = vari.UnitTestResult @@ -103,6 +103,12 @@ func RetrieveUnitResult() (suites []model.UnitTestSuite, resultDir string) { if err == nil { testSuite = ConvertRobotResult(robotResult) } + } else if vari.UnitTestType == "cypress" { + cyResult := model.CypressTestsuites{} + err = xml.Unmarshal([]byte(content), &cyResult) + if err == nil { + testSuite = ConvertCyResult(cyResult) + } } if err == nil { @@ -373,3 +379,43 @@ func RetrieveRobotTests(suite model.RobotSuite, tests *[]model.RobotTest) { *tests = append(*tests, test) } } + +func ConvertCyResult(result model.CypressTestsuites) model.UnitTestSuite { + testSuite := model.UnitTestSuite{} + + for _, suite := range result.Testsuites { + if suite.Name == "Root Suite" { + continue + } + + templ := "20060102 15:04:05.000" + duration := suite.Time + startTime, _ := time.ParseInLocation(templ, suite.Timestamp, time.Local) + //endTime := time.Unix(startTime.Unix() + int64(duration), 0) + + testSuite.Duration = int64(duration) + testSuite.Time = float32(startTime.Unix()) + + for _, cs := range suite.Testcases { + caseResult := model.UnitResult{} + caseResult.TestSuite = suite.Name + caseResult.Title = cs.Name + caseResult.Duration = float32(cs.Time) + + if len(cs.Failures) > 0 { + caseResult.Status = "fail" + + fail := model.Failure{} + fail.Type = cs.Failures[0].Type + fail.Desc = cs.Failures[0].Message + caseResult.Failure = &fail + } else { + caseResult.Status = "pass" + } + + testSuite.TestCases = append(testSuite.TestCases, caseResult) + } + } + + return testSuite +} diff --git a/src/utils/const/const.go b/src/utils/const/const.go index 1d8039c7..4e42e855 100644 --- a/src/utils/const/const.go +++ b/src/utils/const/const.go @@ -41,11 +41,12 @@ var ( RequestTypePathInfo = "PATH_INFO" - AutoTestTypes = []string{"selenium", "appium"} - UnitTestTypeJunit = "junit" - UnitTestTypeTestNG = "testng" - UnitTestTypeRobot = "robot" - UnitTestTypes = []string{UnitTestTypeJunit, UnitTestTypeTestNG, UnitTestTypeRobot, + AutoTestTypes = []string{"selenium", "appium"} + UnitTestTypeJunit = "junit" + UnitTestTypeTestNG = "testng" + UnitTestTypeRobot = "robot" + UnitTestTypeCypress = "cypress" + UnitTestTypes = []string{UnitTestTypeJunit, UnitTestTypeTestNG, UnitTestTypeRobot, UnitTestTypeCypress, "phpunit", "pytest", "jest", "cppunit", "gtest", "qtest"} UnitTestToolMvn = "mvn" UnitTestToolRobot = "robot" diff --git a/src/ztf.go b/src/ztf.go index cba5b7ad..0d35b75a 100644 --- a/src/ztf.go +++ b/src/ztf.go @@ -74,8 +74,8 @@ func main() { flagSet.BoolVar(&noNeedConfirm, "y", false, "") flagSet.BoolVar(&vari.Verbose, "verbose", false, "") - flagSet.IntVar(&vari.Port, "P", 8848, "") - flagSet.IntVar(&vari.Port, "port", 8848, "") + flagSet.IntVar(&vari.Port, "P", 0, "") + flagSet.IntVar(&vari.Port, "port", 0, "") flagSet.StringVar(&vari.Platform, "M", string(serverConst.Vm), "") var placeholder string -- GitLab