diff --git a/src/gen-project.go b/src/gen-project.go new file mode 100644 index 0000000000000000000000000000000000000000..090bb307ac6880c5d5c84e63202192d10092887e --- /dev/null +++ b/src/gen-project.go @@ -0,0 +1,144 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + "strconv" + "strings" +) + +type Response struct { + Code int + Cases []TestCase +} + +type TestCase struct { + Id int + Title string + Steps []TestStep +} + +type TestStep struct { + Id int + Title string + Steps []TestStep + + Expect string + IsGroup bool + IsCheckPoint bool +} + +func ReadAll(filePth string) []byte { + buf, err := ioutil.ReadFile(filePth) + if err != nil { + return nil + } + + return buf +} + +func DealwithTestCase(tc TestCase, langType string) { + caseId := tc.Id + caseTitle := tc.Title + + steps := []string{} + expects := []string{} + srcCode := []string{} + + level := 1 + + for _, ts := range tc.Steps { + DealwithTestStep(ts, langType, level, &steps, &expects, &srcCode) + } + + template := ReadAll("xdoc/script-template.txt") + content := string(fmt.Sprintf(string(template), langType, caseTitle, caseId, + strings.Join(steps, "\n"), strings.Join(expects, "\n"), strings.Join(srcCode, "\n"))) + + fmt.Println(content) +} + +func DealwithTestStep(ts TestStep, langType string, level int, + steps *[]string, expects *[]string, srcCode *[]string) { + isGroup := ts.IsGroup + isCheckPoint := ts.IsCheckPoint + + stepId := ts.Id + stepTitle := ts.Title + stepExpect := ts.Expect + + // 处理steps + stepLine := "" + + var stepType string + if isGroup { + stepType = "group" + } else { + stepType = "step" + } + stepLine += stepType + strconv.Itoa(stepId) + " // " + stepTitle + if isCheckPoint { + stepLine = "@" + stepLine + } + i := level + for { + stepLine = " " + stepLine + i-- + if i == 0 { + break + } + } + stepLineSimple := strings.Replace(strings.TrimLeft(stepLine, " "), "//", "-", -1) + *steps = append(*steps, stepLine) + + // 处理expects + + if isCheckPoint { + expectsLine := "" + + expectsLine = "# " + stepLineSimple + " " + stepExpect + "\n" + expectsLine += "<期望值字符串, 可以有多行>\n" + + *expects = append(*expects, expectsLine) + } + + // 处理srcCode + + if isCheckPoint { + codeLine := "" + + codeLine = "# " + stepLineSimple + "\n" + codeLine += "// 此处编写上述验证点代码 \n" + + *srcCode = append(*srcCode, codeLine) + } + + if isGroup { + for _, tsChild := range ts.Steps { + DealwithTestStep(tsChild, langType, level+1, steps, expects, srcCode) + } + } +} + +func main() { + if len(os.Args) < 2 { + fmt.Println("usage: gen-project.go ") + } + + caseFile, langType := os.Args[1], os.Args[2] + buf := ReadAll(caseFile) + + var resp Response + json.Unmarshal(buf, &resp) + + if resp.Code != 1 { + fmt.Println(string(buf)) + return + } + + for _, testCase := range resp.Cases { + DealwithTestCase(testCase, langType) + } +} diff --git a/src/test.go b/src/test.go deleted file mode 100644 index 44962e271c6d723a2e4cb72e5a9478a27f531a0c..0000000000000000000000000000000000000000 --- a/src/test.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("helloworld") -} diff --git a/xdoc/script-template-sample.txt b/xdoc/script-template-sample.txt new file mode 100644 index 0000000000000000000000000000000000000000..431b6bca0e6f997e5ec87a807023db2f1e91ceb5 --- /dev/null +++ b/xdoc/script-template-sample.txt @@ -0,0 +1,31 @@ + diff --git a/xdoc/script-template.txt b/xdoc/script-template.txt new file mode 100644 index 0000000000000000000000000000000000000000..ebbb67c7cd86739ab4e64fb15f743003560080bf --- /dev/null +++ b/xdoc/script-template.txt @@ -0,0 +1,16 @@ + diff --git a/xdoc/tc.json b/xdoc/test-case.json similarity index 54% rename from xdoc/tc.json rename to xdoc/test-case.json index b7743a38a0ad23ca3ddc1f7315151d79f54c8235..8d0fb8edbb7a5a01e916f8092ea148c11b5d228a 100644 --- a/xdoc/tc.json +++ b/xdoc/test-case.json @@ -7,21 +7,24 @@ "steps": [ { "id": 1000, - "action": "打开登录页面", + "title": "打开登录页面", "expect": "", - "group": false + "isGroup": false, + "isCheckPoint": false }, { "id": 1010, - "action": "输入正确的用户名和密码", + "title": "输入正确的用户名和密码", "expect": "", - "group": false + "isGroup": false, + "isCheckPoint": false }, { "id": 1020, - "action": "点击'登录'按钮", + "title": "点击'登录'按钮", "expect": "用户成功登录", - "group": false + "isGroup": false, + "isCheckPoint": true } ] }, @@ -31,45 +34,39 @@ "steps": [ { "id": 2000, - "action": "连续输入3次错误的密码", - "expect": "", - "group": false + "title": "连续输入3次错误的密码" }, { "id": 2010, - "action": "第4次尝试登录", + "title": "第4次尝试登录", "expect": "系统提示账号被锁定", - "group": false + "isCheckPoint": true }, { "id": 2100, - "action": "不连续输入3次错误的密码", - "expect": "", - "group": true, + "title": "不连续输入3次错误的密码", + "isGroup": true, "steps": [ { "id": 2101, - "action": "输入2次错误的密码", - "expect": "", - "group": true + "title": "输入2次错误的密码", + "isGroup": false }, { "id": 2102, - "action": "输入1次正确的密码", - "expect": "", - "group": true + "title": "输入1次正确的密码", + "isGroup": false }, { "id": 2103, - "action": "再输入1次错误的密码", - "expect": "", - "group": true + "title": "再输入1次错误的密码", + "isGroup": false }, { "id": 2104, - "action": "再输入1次正确的密码", + "title": "再输入1次正确的密码", "expect": "登录成功,账号未被锁定", - "group": true + "isCheckPoint": true } ] } diff --git a/xdoc/test-script.php b/xdoc/test-script.php new file mode 100644 index 0000000000000000000000000000000000000000..896fe8e58b18eced33d5bab4db3970b64cf98a32 --- /dev/null +++ b/xdoc/test-script.php @@ -0,0 +1,32 @@ + + +# @step2104 - 再输入1次正确的密码 登录成功,账号未被锁定 +<期望值字符串, 可以有多行> + +TC; + +// 此处编写操作步骤代码 + +# @step2010 - 第4次尝试登录 +// 此处编写上述验证点代码 + +# @step2104 - 再输入1次正确的密码 +// 此处编写上述验证点代码 + + +?> \ No newline at end of file