提交 4304947a 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

generate test scripts from sample manual testcase

上级 82c462f3
...@@ -3,49 +3,20 @@ package main ...@@ -3,49 +3,20 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "model"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"utils"
) )
type Response struct { func DealwithTestCase(tc model.TestCase, langType string) {
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 caseId := tc.Id
caseTitle := tc.Title caseTitle := tc.Title
steps := []string{} steps := make([]string, 0)
expects := []string{} expects := make([]string, 0)
srcCode := []string{} srcCode := make([]string, 0)
level := 1 level := 1
...@@ -53,21 +24,21 @@ func DealwithTestCase(tc TestCase, langType string) { ...@@ -53,21 +24,21 @@ func DealwithTestCase(tc TestCase, langType string) {
DealwithTestStep(ts, langType, level, &steps, &expects, &srcCode) DealwithTestStep(ts, langType, level, &steps, &expects, &srcCode)
} }
template := ReadAll("xdoc/script-template.txt") template := utils.ReadFile("xdoc/script-template.txt")
content := string(fmt.Sprintf(string(template), langType, caseTitle, caseId, content := string(fmt.Sprintf(string(template), langType, caseTitle, caseId,
strings.Join(steps, "\n"), strings.Join(expects, "\n"), strings.Join(srcCode, "\n"))) strings.Join(steps, "\n"), strings.Join(expects, "\n"), strings.Join(srcCode, "\n")))
fmt.Println(content) fmt.Println(content)
} }
func DealwithTestStep(ts TestStep, langType string, level int, func DealwithTestStep(ts model.TestStep, langType string, level int,
steps *[]string, expects *[]string, srcCode *[]string) { steps *[]string, expects *[]string, srcCode *[]string) {
isGroup := ts.IsGroup isGroup := ts.IsGroup
isCheckPoint := ts.IsCheckPoint isCheckPoint := ts.IsCheckPoint
stepId := ts.Id stepId := ts.Id
stepTitle := ts.Title stepTitle := ts.Title
stepExpect := ts.Expect // stepExpect := ts.Expect
// 处理steps // 处理steps
stepLine := "" stepLine := ""
...@@ -94,12 +65,11 @@ func DealwithTestStep(ts TestStep, langType string, level int, ...@@ -94,12 +65,11 @@ func DealwithTestStep(ts TestStep, langType string, level int,
*steps = append(*steps, stepLine) *steps = append(*steps, stepLine)
// 处理expects // 处理expects
if isCheckPoint { if isCheckPoint {
expectsLine := "" expectsLine := ""
expectsLine = "# " + stepLineSimple + " " + stepExpect + "\n" expectsLine = "# \n" // + stepLineSimple + " " + stepExpect + "\n"
expectsLine += "<期望值字符串, 可以有多行>\n" expectsLine += "<" + stepType + strconv.Itoa(stepId) + " 期望结果, 可以有多行>\n"
*expects = append(*expects, expectsLine) *expects = append(*expects, expectsLine)
} }
...@@ -128,9 +98,9 @@ func main() { ...@@ -128,9 +98,9 @@ func main() {
} }
caseFile, langType := os.Args[1], os.Args[2] caseFile, langType := os.Args[1], os.Args[2]
buf := ReadAll(caseFile) buf := utils.ReadFile(caseFile)
var resp Response var resp model.Response
json.Unmarshal(buf, &resp) json.Unmarshal(buf, &resp)
if resp.Code != 1 { if resp.Code != 1 {
......
package model
type Response struct {
Code int
Cases []TestCase
}
type TestCase struct {
Id int
Title string
Steps []TestStep
}
type TestStep struct {
TestCase
Expect string
IsGroup bool
IsCheckPoint bool
}
package utils
import "io/ioutil"
func ReadFile(filePth string) []byte {
buf, err := ioutil.ReadFile(filePth)
if err != nil {
return nil
}
return buf
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册