请问怎么在xcrsult的文件中解析出来执行日志啊
YaoJuan opened this issue · comments
在单次测试执行中,可以在显示包内容中看到.txt的命令行日志文件,但是测试执行完之后里面的没了,请问怎么解析出对应的日志文件呢
xcodebuild test
执行时会输出日志,可以直接在console中查看,也可以输出到文件中查看。
xcodebuild test -workspace Demo.xcworkspace -scheme Demo -derivedDataPath "${BUILD_DIR}/" -destination "${SIMULATOR_PLATFORM}" > test.log
@YaoJuan 明白你的意思了。
单元测试执行完毕后,会移除执行过程日志,所以你会看到日志文件没了。
如果要获取执行日志,需要统一使用xcresulttool
来提取。
Demo代码,将日志提取到./test.log
目录下:
# 解析出tests_ref中的id,用于获取下一步的数据
actions_invocation_record = XCResult::ActionsInvocationRecord.new(result_bundle_object)
diagnostics_refs = actions_invocation_record.actions.map do |action|
action.action_result.diagnostics_ref
end.compact
# demo代码,取出第一个id,并提取日志
id = diagnostics_refs.map(&:id).first
`xcrun xcresulttool export --type directory --id #{id} --output-path ./test.log --path #{path}`
代码执行上下文可以参考
https://github.com/JerryChu/UnitTestParser/blob/master/unitTestInfo.rb#L24
@YaoJuan 明白你的意思了。
单元测试执行完毕后,会移除执行过程日志,所以你会看到日志文件没了。
如果要获取执行日志,需要统一使用xcresulttool
来提取。Demo代码,将日志提取到
./test.log
目录下:# 解析出tests_ref中的id,用于获取下一步的数据 actions_invocation_record = XCResult::ActionsInvocationRecord.new(result_bundle_object) diagnostics_refs = actions_invocation_record.actions.map do |action| action.action_result.diagnostics_ref end.compact # demo代码,取出第一个id,并提取日志 id = diagnostics_refs.map(&:id).first `xcrun xcresulttool export --type directory --id #{id} --output-path ./test.log --path #{path}`代码执行上下文可以参考
https://github.com/JerryChu/UnitTestParser/blob/master/unitTestInfo.rb#L24
非常感谢