如何从swift运行xcodebuild测试命令?

如何从swift运行xcodebuild测试命令?,xcode,swift,macos,swift2,osx-elcapitan,Xcode,Swift,Macos,Swift2,Osx Elcapitan,我有一个ios项目,在那里我编写了ios ui测试用例 现在我已经创建了另一个osx(swift)命令行工具,我想从主文件运行我的ios项目ui测试 为此,我使用以下命令: xcodebuild test -project /Users/usernamer/Desktop/Xocde/ios-ui-automation-demo-master/ios-ui-automation-demo.xcodeproj -scheme ios-ui-automation-demo -destination

我有一个ios项目,在那里我编写了ios ui测试用例

现在我已经创建了另一个osx(swift)命令行工具,我想从主文件运行我的ios项目ui测试

为此,我使用以下命令:

xcodebuild test -project /Users/usernamer/Desktop/Xocde/ios-ui-automation-demo-master/ios-ui-automation-demo.xcodeproj -scheme ios-ui-automation-demo -destination 'platform=iOS Simulator,name=iPad Air'
如果我从终端运行此命令,那么ios项目ui测试将正常运行

但是,如果从osx命令行工具swift文件(在新的osx项目中)运行该命令,则会显示错误。代码是

import Foundation

func shell(args: String...) -> Int32 {
let task = NSTask()
task.launchPath = "/usr/bin/xcodebuild"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}

print("This is test version edit")

shell("xcodebuild test -project /Users/username/Desktop/Xocde/ios-ui-automation-demo-master/ios-ui-automation-demo.xcodeproj -scheme ios-ui-automation-demo -destination 'platform=iOS Simulator,name=iPad Air'")
此代码显示以下错误:

    xcodebuild: error: The directory /Users/username/Library/Developer/Xcode/DerivedData/automationProject-brxvyfplrimnekchsaaenmecydkp/Build/Products/Debug does not contain an Xcode project.

 Program ended with exit code: 9
这里automationProject是我运行主文件以运行ios ui测试的osx项目名称


请帮助我,我的错误是什么。

使用task.launchPath,如下所示:

 task.launchPath = "/usr/bin/env"
最后使用如下函数:

shell("xcodebuild", "test","-project","/Users/username/Desktop/Xocde/ios-ui-automation-demo-master/ios-ui-automation-demo.xcodeproj","-scheme","ios-ui-automation-demo","-destination","platform=iOS Simulator,name=iPad Air")

使用task.launchPath,如下所示:

 task.launchPath = "/usr/bin/env"
最后使用如下函数:

shell("xcodebuild", "test","-project","/Users/username/Desktop/Xocde/ios-ui-automation-demo-master/ios-ui-automation-demo.xcodeproj","-scheme","ios-ui-automation-demo","-destination","platform=iOS Simulator,name=iPad Air")

@Eric D谢谢你的帮助。。。让我查一下,我会知道的you@EricD,实际上,如何使用启动路径切换到ios xcode proj dir?因为我使用/usr/bin/xcodebuild作为启动路径path@EricD谢谢你的帮助。。。让我查一下,我会知道的you@EricD,实际上,如何使用启动路径切换到ios xcode proj dir?因为我使用/usr/bin/xcodebuild作为启动路径