将字典作为值传递给 launchArguments 以进行 UI 测试

问题描述 投票:0回答:1

我正在尝试传递一个表示为 launchArguments 字典的值,以便运行 UI 测试。

所以,我尝试将字典转换为字符串格式并像这样传递它:

let dic = ["Key1": "Value1", "Key2": "Value2"]
do {
    let data = try JSONEncoder().encode(dic)
    if let value = String(data: data, encoding: .utf8) {
        launchArguments += [ "-launchKey", value ]
    }
} catch {
    print("Error encoding launchArguments: \(error.localizedDescription)")
}

当应用程序启动时,它不会向 UserDefaults 添加字典。它也不提供任何信息。可能有什么问题?

ios swift xcode-ui-testing xcuitest xctestcase
1个回答
0
投票

launchArguments 是字符串数组: https://developer.apple.com/documentation/xctest/xcuiaapplication/1500477-launcharguments

launchEnvironment 是一个字典: https://developer.apple.com/documentation/xctest/xcuiaapplication/1500427-launchenvironment

您可以访问 launchEnvironment 密钥: ProcessInfo.processInfo.environment["yourKey"]

© www.soinside.com 2019 - 2024. All rights reserved.