Class: Fastlane::Actions::XcodebuildonlytestingAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/xcodebuildonlytesting/actions/xcodebuildonlytesting_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



45
46
47
# File 'lib/fastlane/plugin/xcodebuildonlytesting/actions/xcodebuildonlytesting_action.rb', line 45

def self.authors
  ["Luís Esteves"]
end

.available_optionsObject



58
59
60
61
62
63
64
# File 'lib/fastlane/plugin/xcodebuildonlytesting/actions/xcodebuildonlytesting_action.rb', line 58

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :reportLocation,
                                 description: "junit report location",
                                 optional: false),
  ]
end

.descriptionObject



41
42
43
# File 'lib/fastlane/plugin/xcodebuildonlytesting/actions/xcodebuildonlytesting_action.rb', line 41

def self.description
  "Creates a array of tests from a junit to feed the xcodebuild only-testing"
end

.detailsObject



53
54
55
56
# File 'lib/fastlane/plugin/xcodebuildonlytesting/actions/xcodebuildonlytesting_action.rb', line 53

def self.details
  # Optional:
  "Creates a array of tests from a junit to feed the xcodebuild only-testing"
end

.is_supported?(platform) ⇒ Boolean



66
67
68
# File 'lib/fastlane/plugin/xcodebuildonlytesting/actions/xcodebuildonlytesting_action.rb', line 66

def self.is_supported?(platform)
  platform == :ios
end

.return_valueObject



49
50
51
# File 'lib/fastlane/plugin/xcodebuildonlytesting/actions/xcodebuildonlytesting_action.rb', line 49

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



7
8
9
10
11
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
# File 'lib/fastlane/plugin/xcodebuildonlytesting/actions/xcodebuildonlytesting_action.rb', line 7

def self.run(params)
  UI.message("The xcodebuildonlytesting plugin is working!")

  report_file = File.open(params[:reportLocation]) { |f| REXML::Document.new(f) }

  FastlaneCore::UI.user_error!("Malformed XML test report file given") if report_file.root.nil?
  FastlaneCore::UI.user_error!("Valid XML file is not an Xcode test report") if report_file.get_elements('testsuites').empty?

  failingTests = []
  report_file.elements.each('testsuites') do |testsuites_element|
    
    testsuites_element.elements.each('testsuite') do |testsuite_element|
      testsuiteName = testsuite_element.attribute('name').value
      UI.message("testsuite: #{testsuiteName}".green)
      
      testsuite_element.elements.each('testcase') do |testcase_element|
        className = testcase_element.attribute('classname').value
        testName = testcase_element.attribute('name').value
        testName.slice!('()')

        failure = testcase_element.elements['failure']
        if failure 
          UI.message("Test: #{className} - #{testName}".red)
          failingTests << "#{testsuiteName}/#{className}/#{testName}"
        else
          UI.message("Test: #{className} - #{testName}".green)
        end
      end
    end
  end
  
  return failingTests
end