Aar*_*aer 1 ruby junit xcodebuild fastlane
作为将 XCode 的 UI 测试添加到 CI 流程的一部分,由于测试框架普遍不可靠,我决定在构建失败之前重新运行失败的测试。
我可以通过使用块来避免构建立即失败rescue,这不是问题,并且报告文件(JUnit 和 HTML)的位置是固定的,因此可以使用 File.readlines 等打开。
junit 报告文件的格式是测试套件 -> 测试套件 -> 测试用例 -> 失败消息(如果适用)的级联,然后回退到足以容纳下一个元素。看起来很标准。
然而,在那一点上我有点卡住了(这可能不是正确的道路;首先有没有一个规范的更好的方法来做到这一点?)。在 bash 中,我将使用 grep -B 提取失败消息之前的行,这将是失败测试用例的名称,然后使用 awk 获取相关文本片段。然后我可以使用 -only-testing 参数将简单的两个管道 shell 命令反馈到 scan/xcodebuild 中。
有没有办法在 Ruby 中同样轻松地做到这一点,或者有一个 junit 插件可以让我只读出各个失败测试用例的名称?
如果将来有人遇到这个问题:
def parse_ui_test_report
doc = File.open("#{REPORT_LOCATION}/report.junit") { |f| Nokogiri::XML(f) }
node_tree = doc.css('testcase')
test_identifiers_to_rerun = node_tree.map do |node|
# Test case nodes in the JUNIT XML doc don't have children unless they failed
if node.first_element_child
node.values.join('/').gsub('.','/')
end
end.select {|str| !str.nil? && !str.empty? }
return test_identifiers_to_rerun
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1450 次 |
| 最近记录: |