Class: XCPretty::JUnit

Inherits:
Object
  • Object
show all
Includes:
FormatMethods
Defined in:
lib/xcpretty/reporters/junit.rb

Constant Summary collapse

FILEPATH =
'build/reports/junit.xml'

Constants included from FormatMethods

FormatMethods::EMPTY_STRING

Instance Method Summary collapse

Methods included from FormatMethods

#format_analyze, #format_build_target, #format_check_dependencies, #format_clean, #format_clean_remove, #format_clean_target, #format_codesign, #format_compile, #format_compile_error, #format_compile_xib, #format_copy_strings_file, #format_cpresource, #format_error, #format_generate_dsym, #format_libtool, #format_linking, #format_pbxcp, #format_phase_script_execution, #format_preprocess, #format_process_info_plist, #format_process_pch, #format_test_run_finished, #format_test_run_started, #format_test_suite_started, #format_test_summary

Constructor Details

#initializeJUnit

Returns a new instance of JUnit.



17
18
19
20
21
22
23
24
25
26
# File 'lib/xcpretty/reporters/junit.rb', line 17

def initialize
  load_dependencies
  @directory = `pwd`.strip
  @document  = REXML::Document.new
  @document << REXML::XMLDecl.new('1.0','UTF-8')
  @document.add_element('testsuites')
  @parser    = Parser.new(self)
  @total_tests = 0
  @total_fails = 0
end

Instance Method Details

#finishObject



51
52
53
54
55
56
# File 'lib/xcpretty/reporters/junit.rb', line 51

def finish
  set_test_counters
  @document.root.attributes['tests'] = @total_tests
  @document.root.attributes['failures'] = @total_fails
  write_report_file
end

#format_failing_test(classname, test_case, reason, file) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/xcpretty/reporters/junit.rb', line 40

def format_failing_test(classname, test_case, reason, file)
  test_node = suite(classname).add_element('testcase')
  test_node.attributes['classname'] = classname
  test_node.attributes['name']      = test_case
  fail_node = test_node.add_element('failure')
  fail_node.attributes['message'] = reason
  fail_node.text = file.sub(@directory + '/', '')
  @test_count += 1
  @fail_count += 1
end

#format_passing_test(classname, test_case, time) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/xcpretty/reporters/junit.rb', line 32

def format_passing_test(classname, test_case, time)
  test_node = suite(classname).add_element('testcase')
  test_node.attributes['classname'] = classname
  test_node.attributes['name']      = test_case
  test_node.attributes['time']      = time
  @test_count += 1
end

#handle(line) ⇒ Object



28
29
30
# File 'lib/xcpretty/reporters/junit.rb', line 28

def handle(line)
  @parser.parse(line)
end

#load_dependenciesObject



7
8
9
10
11
12
13
14
15
# File 'lib/xcpretty/reporters/junit.rb', line 7

def load_dependencies
  unless @@loaded ||= false
    require 'fileutils'
    require 'pathname'
    require 'rexml/document'
    require 'rexml/formatters/pretty'
    @@loaded = true
  end
end