Class: Fastlane::Actions::RunTestsAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/run_tests.rb

Direct Known Subclasses

ScanAction

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject

[View source]

67
68
69
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 67

def self.author
  "KrauseFx"
end

.available_optionsObject

[View source]

71
72
73
74
75
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 71

def self.available_options
  require 'scan'

  FastlaneCore::CommanderGenerator.new.generate(Scan::Options.available_options)
end

.categoryObject

[View source]

119
120
121
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 119

def self.category
  :testing
end

.descriptionObject

[View source]

51
52
53
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 51

def self.description
  "Easily run tests of your iOS app (via _scan_)"
end

.detailsObject

[View source]

55
56
57
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 55

def self.details
  "More information: https://docs.fastlane.tools/actions/scan/"
end

.example_codeObject

[View source]

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 93

def self.example_code
  [
    'run_tests',
    'scan # alias for "run_tests"',
    'run_tests(
      workspace: "App.xcworkspace",
      scheme: "MyTests",
      clean: false
    )',
    '# Build For Testing
    run_tests(
       derived_data_path: "my_folder",
       build_for_testing: true
    )',
    '# run tests using derived data from prev. build
    run_tests(
       derived_data_path: "my_folder",
       test_without_building: true
    )',
    '# or run it from an existing xctestrun package
    run_tests(
       xctestrun: "/path/to/mytests.xctestrun"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

[View source]

87
88
89
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 87

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.outputObject

[View source]

77
78
79
80
81
82
83
84
85
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 77

def self.output
  [
    ['SCAN_DERIVED_DATA_PATH', 'The path to the derived data'],
    ['SCAN_GENERATED_PLIST_FILE', 'The generated plist file'],
    ['SCAN_GENERATED_PLIST_FILES', 'The generated plist files'],
    ['SCAN_GENERATED_XCRESULT_PATH', 'The path to the generated .xcresult'],
    ['SCAN_ZIP_BUILD_PRODUCTS_PATH', 'The path to the zipped build products']
  ]
end

.return_typeObject

[View source]

63
64
65
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 63

def self.return_type
  :hash
end

.return_valueObject

[View source]

59
60
61
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 59

def self.return_value
  'Outputs hash of results with the following keys: :number_of_tests, :number_of_failures, :number_of_retries, :number_of_tests_excluding_retries, :number_of_failures_excluding_retries'
end

.run(values) ⇒ Object

[View source]

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'fastlane/lib/fastlane/actions/run_tests.rb', line 12

def self.run(values)
  require 'scan'
  manager = Scan::Manager.new

  begin
    results = manager.work(values)

    zip_build_products_path = Scan.cache[:zip_build_products_path]
    Actions.lane_context[SharedValues::SCAN_ZIP_BUILD_PRODUCTS_PATH] = zip_build_products_path if zip_build_products_path

    return results
  rescue FastlaneCore::Interface::FastlaneBuildFailure => ex
    # Specifically catching FastlaneBuildFailure to prevent build/compile errors from being
    # silenced when :fail_build is set to false
    # :fail_build should only suppress testing failures
    raise ex
  rescue => ex
    if values[:fail_build]
      raise ex
    end
  ensure
    if Scan.cache && (result_bundle_path = Scan.cache[:result_bundle_path])
      Actions.lane_context[SharedValues::SCAN_GENERATED_XCRESULT_PATH] = File.absolute_path(result_bundle_path)
    else
      Actions.lane_context[SharedValues::SCAN_GENERATED_XCRESULT_PATH] = nil
    end

    unless values[:derived_data_path].to_s.empty?
      plist_files_before = manager.plist_files_before || []

      Actions.lane_context[SharedValues::SCAN_DERIVED_DATA_PATH] = values[:derived_data_path]
      plist_files_after = manager.test_summary_filenames(values[:derived_data_path])
      all_test_summaries = (plist_files_after - plist_files_before)
      Actions.lane_context[SharedValues::SCAN_GENERATED_PLIST_FILES] = all_test_summaries
      Actions.lane_context[SharedValues::SCAN_GENERATED_PLIST_FILE] = all_test_summaries.last
    end
  end
end