Перезапустить не удалось XCTests в Fastlane - PullRequest
0 голосов
/ 18 февраля 2020

Я пытаюсь перезапустить тесты, которые не прошли через 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. В отчете. xml просто показаны пройденные тесты.

...