gpt4 book ai didi

Swift:如何通过运行 shell 命令重置模拟器

转载 作者:行者123 更新时间:2023-11-28 10:52:35 28 4
gpt4 key购买 nike

我试图在每次测试后重置模拟器。我找到了最好的方法,就是执行

xcrun simctl erase all

但我不知道如何在swift文件中添加一个shell命令来执行它。

我试过了

import Foundation
func shell(_ args: String...) -> Int32 {
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}

但出现错误,未找到进程 u\identifier请帮忙。我正在尝试在每次测试后重置模拟器。

我可以通过命令行从模拟器中卸载特定的应用程序吗?或每个测试之间的任何其他方式,在 tearDown()

最佳答案

我有一个类似的问题,并且能够通过 SBTUITestTunnel 解决它.我选择使用这个框架,因为我还必须在测试应用程序和我的实际应用程序之间进行通信以配置测试状态。

通过实现 SBTUITestTunnel,您可以指定启动选项,您需要的是 SBTUITunneledApplicationLaunchOptionResetFilesystem。

app.launchTunnel(withOptions: [SBTUITunneledApplicationLaunchOptionResetFilesystem]) {
// do additional setup before the app launches
// i.e. prepare stub request, start monitoring requests
}

我建议您看看 SBTUITestTunnel,因为它可以让您做一些其他非常强大的事情。

关于Swift:如何通过运行 shell 命令重置模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45363200/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com