Xcode11 如何从XCUI单元测试生成的.xcresult包中收集stdout和std错误?

Xcode11 如何从XCUI单元测试生成的.xcresult包中收集stdout和std错误?,xcode11,xcuitest,Xcode11,Xcuitest,在Xcode 10及以下版本中,可以使用以下shell命令从指定的-resultBundlePath中找到并提取测试套件运行的stdout和stderror: cp-fv$(查找$resultBundlePath/1_Test-print | grep TestSuite1 | grep'standardpoutputandstandarderrror.txt'| xargs)TestSuite1Xctestrun.log“ 对于Xcode 11+,在捆绑包中不再找到此文件 从xcbundle中

在Xcode 10及以下版本中,可以使用以下shell命令从指定的-resultBundlePath中找到并提取测试套件运行的
stdout
stderror

cp-fv$(查找$resultBundlePath/1_Test-print | grep TestSuite1 | grep'standardpoutputandstandarderrror.txt'| xargs)TestSuite1Xctestrun.log“

对于Xcode 11+,在捆绑包中不再找到此文件

从xcbundle中提取它的位置和方式?

xcrun XCREATTOOL--formatDescription
显示有一个logRef键,该键具有指向日志的唯一值,如果我们知道该项的ID,就可以查询该日志

使用jq,我能够完成这项任务

首先,我们获取
logRef
的id,然后从
.xcsresult
捆绑包中提取其值到文本文件中

# find the id that points to the location of the encoded file in the .xcresult bundle
id=$(xcrun xcresulttool get --format json --path Tests.xcresult | jq '.actions._values[]' | jq -r '.actionResult.logRef.id._value')
# export the log found at the the id in the .xcresult bundle
xcrun xcresulttool export --path Tests.xcresult --id $id --output-path TestsStdErrorStdout.log --type file

需要注意的一点是,这不是原始日志。它实际上是从XResultTool导出的包含日志的ActionLogSection对象。因此,如果您从Xcode导出日志并尝试使用diff,您会注意到文件中有您意想不到的附加数据。我的工作场所将此添加到了Xcode 11 XResult()的解析工具中如果有人愿意使用自制的命令行工具来实现这一点。