dyang/merge_junit_report

View on GitHub
fastlane/Fastfile

Summary

Maintainability
Test Coverage
lane :test do |options|
  base_derived_data_path = options[:derived_data_path]
  test_reports = []

  begin
    retry_count ||= 0

    # Putting output and derived data of each run into its own directory
    output_directory_for_this_run = "#{base_derived_data_path}/run#{retry_count}"
    options[:derived_data_path] = output_directory_for_this_run
    options[:output_directory] = output_directory_for_this_run

    scan(options)

    last_report_file_path = "#{options[:output_directory]}/#{options[:custom_report_file_name]}"
    test_reports << last_report_file_path
    merge_junit_report(input_files: test_reports)

  rescue => e
    UI.important("failure noted: #{e}")

    last_report_file_path = "#{options[:output_directory]}/#{options[:custom_report_file_name]}"
    test_reports << last_report_file_path

    if (retry_count += 1) < 3
      setup_fragile_tests_for_rescan(
        project_path: options[:project],
        scheme: options[:scheme],
        report_filepath: last_report_file_path
      )
      retry
    end

    merge_junit_report(input_files: test_reports)
    raise e
  end
end

lane :merge do
  merge_junit_report(input_files: ['build/run0/report.xml', 'build/run1/report.xml', 'build/run2/report.xml'])
end