zoukankan      html  css  js  c++  java
  • Xcodebuild稳定性测试go脚本

    [本文出自天外归云的博客园]

    简单封装下xcodebuild test命令,写一个执行xcode测试的go程序,可以设定单case执行次数,也可以二次组装调用进行多个case的测试,代码如下:

    package main
    
    import (
        "flag"
        "fmt"
        "os/exec"
        "strings"
    )
    
    func qnegTestRunner(workspacePath string, scheme string, targetMethod string) (testResult int) {
        targets := strings.Split(targetMethod, "/")
        className := targets[1]
        methodName := targets[2]
        var err error
        var cmd *exec.Cmd
        var result []byte
        commandString := fmt.Sprintf("xcodebuild test -workspace %s -scheme %s -destination 'platform=iOS Simulator,name=iPhone 7,OS=12.2' -only-testing:%s", workspacePath, scheme, targetMethod)
        cmd = exec.Command("/bin/bash", "-c", commandString)
        result, err = cmd.Output()
        passedSign := fmt.Sprintf("'-[%s %s]' passed", className, methodName)
        if strings.Contains(string(result), passedSign) {
            testResult = 1
        } else {
            fmt.Println(commandString)
            fmt.Println(strings.Trim(string(result), "
    "))
            fmt.Println(err)
            testResult = 0
        }
        return
    }
    
    /*
    终端执行该脚本命令如下:
    go run exeTest.go -exeCount 3 -projectPath "/Users/admin/Desktop/zenki/XX" -scheme "Scheme" -targetMethod "Scheme/ClassName/methodName"
    */
    func main() {
        var targetMethod = flag.String("targetMethod", "", "目标方法")
        var exeCount = flag.Int("exeCount", 3, "运行次数")
        var projectPath = flag.String("projectPath", "/Users/admin/Desktop/zenki/XX", "项目路径")
        var scheme = flag.String("scheme", "", "选择主题")
        flag.Parse()
        workspacePath := fmt.Sprintf("%s%s", *projectPath, "/XX.xcworkspace")
        finalResult := 0
        for index := 1; index <= *exeCount; index++ {
            fmt.Println(fmt.Printf("[%d time execute] %s", index, *targetMethod))
            finalResult += qnegTestRunner(workspacePath, *scheme, *targetMethod)
        }
        if finalResult == *exeCount {
            fmt.Println(fmt.Sprintf("Execute %d times, all passed.", *exeCount))
        } else {
            fmt.Println(fmt.Sprintf("Execute %d times, %d times passed.", *exeCount, finalResult))
        }
    }
  • 相关阅读:
    AngularJS:实现动态添加输入控件功能
    Openfire:XMPP的几种消息类型
    Openfire:重新配置openfire
    Clojure:日期操作方法
    Openfire:通过Servlet群发消息
    Openfire:访问Servlet时绕开Openfire的身份验证
    Clojure:解决selmer模板不刷新的问题
    Intellij Idea 13:运行Clojure的repl环境
    MVC.Net 5:允许保存和输出Html内容
    BAE Flask UEditor 使用七牛云
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/11725680.html
Copyright © 2011-2022 走看看