首页 > 解决方案 > 在 Fastlane 中重新启动失败的 XCTest

问题描述

我正在尝试重新启动通过 Fastlane 失败的测试。

这是我正在使用的脚本,但没有取得多大成功。不工作的部分是 find_failed_tests。由于某种原因,失败的测试不在 junit 报告中。

@test_retries = 3
TARGET_DEVICES = ["iPad Pro (9.7-inch)"]

lane :testRetry do
    testNames = ["Example_UITests/SearchForm_TestA", "Example_UITests/SearchForm_TestB"]
    UI.message("Testing only tests: #{testNames}")

    begin
        scan(
        scheme: "Example",
        devices: TARGET_DEVICES,
        output_types: 'junit',
        fail_build: false,
            only_testing: testNames,
            clean: true
      )
    rescue

       while @test_retries > 0
         failed_tests = find_failed_tests
         UI.message("Retrying failed tests: #{failed_tests}")

       break if failed_tests.empty?
       @test_retries -= 1
       scan(
             scheme: "Example",
         devices: TARGET_DEVICES,
         output_types: 'junit',
         fail_build: @test_retries.zero?,
         only_testing: failed_tests,
             clean: true
       )
        end
    end
end

def find_failed_tests
    report = File.open('test_output/report.junit') { |f| Nokogiri::XML(f) }
    suite_name = report.xpath('testsuites/@name').to_s.split('.')[0]

    test_cases = report.xpath('//testcase')

    only_testing = []
    test_cases.each do |test_case|

        next if test_case.xpath('failure').empty?

    test_class = test_case.xpath('@classname').to_s.split('.')[1]
    test_name = test_case.xpath('@name')
    only_testing << "#{suite_name}/#{test_class}/#{test_name}"
    end

    only_testing.join(',')
end

我遇到的问题是junit中没有报告失败的测试。report.xml 只显示通过的测试。

标签: swiftxctestfastlane

解决方案


推荐阅读