2012-01-06 23 views
9

Tôi đang sử dụng tập lệnh UIAutomation để kiểm tra ứng dụng iOS của mình. Tôi đã quản lý để có được các kịch bản chạy từ dòng lệnh nhưng bây giờ tôi cần phải chuyển đổi đầu ra (vượt qua/thất bại) trong một định dạng mà Jenkins có thể hiểu, lý tưởng phong cách JUnit.Làm thế nào tôi có thể biến đầu ra của các kiểm tra UIAutomation iOS của tôi thành đầu ra kiểu JUnit cho Jenkins?

Có ai đã viết bất kỳ tập lệnh nào để làm điều này trước khi tôi thử & viết một?

Rất cám ơn

+0

thậm chí tôi đang cố gắng điều tương tự. bạn đã tích hợp tất cả các bước với nhau thông qua jenkins..code checkin -> build -> chạy script atomation của bạn -> lấy kết quả kiểm tra ra khỏi nó xin vui lòng cho tôi biết nếu bạn đã thử trên những thứ – vikas

+0

Tôi đã tìm kiếm rộng rãi và thiên đường ' t tìm thấy bất cứ điều gì. Chúng tôi chỉ có một cái gì đó bị tấn công với nhau cho mục đích riêng của chúng tôi. Hãy làm một cái gì đó reuseable. Tôi sẽ sử dụng nó. –

+0

Ý bạn là gì khi "chuyển đổi nó thành một định dạng jenkins hiểu"? nếu bạn muốn jenkins chỉ để biết liệu xây dựng đã vượt qua hay thất bại theo các bài kiểm tra thì nó có thể được thực hiện bằng cách phân tích nó trong một kịch bản lệnh shell và chạy nó như là một bước xây dựng. nếu không, nếu bạn muốn sử dụng các khả năng xuất bản báo cáo jenkins và có được một báo cáo tốt đẹp ở cuối bạn phải chuyển đổi nó thành kiểu Junit xml, tôi nghĩ rằng điều duy nhất của nó là biết cách phân tích cú pháp – Michael

Trả lời

3

lẽ bạn có thể có một cái nhìn tại địa chỉ: https://github.com/shaune/jasmine-ios-acceptance-tests

Edit: Tôi cũng đã tránh sử dụng hoa nhài. Để 'lắng nghe' bắt đầu, vượt qua thất bại và thử nghiệm, tôi đã chỉ đơn giản là thay thế UIALogger.logStart, UIALogger.logFailUIALogger.logPass:

(function() { 
    // An anonymous function wrapper helps you keep oldSomeFunction private  
    var oldSomeFunction = UIALogger.logStart; 
    UIALogger.logStart = function() { 
    //UIALogger.logDebug("intercepted a logStart : " + arguments); 
    OKJunitLogger.reportTestSuiteStarting(arguments[0]); 
    oldSomeFunction.apply(this, arguments); 
    } 
})(); 
+0

. để tránh sử dụng Jasmine và thay vào đó hãy sử dụng thư viện [tuneup.js] (https://github.com/alexvollmer/tuneup_js) để đơn giản hóa mọi thứ. Tôi đã đánh dấu câu trả lời của bạn là chính xác vì nó đáp ứng yêu cầu của tôi mặc dù, cảm ơn bạn. – MandyW

+0

Tôi chỉ chỉnh sửa câu trả lời của mình để cho bạn thấy giải pháp mà tôi đã chọn để triển khai –

+0

@kenji Bạn có thể giải thích một chút về cách thức và nơi bạn sử dụng chức năng này không? – stackErr

1

tôi bealive bạn sẽ tìm thấy những gì bạn cần ở đây: https://github.com/shinetech/jenkins-ios-example

Những gì bạn đang quan tâm trong là cuộc gọi script "ocunit2junit.rb"

Tôi đã sử dụng nó cho một dự án, nó hoạt động rất tốt.

#!/usr/bin/ruby 
# 
# ocunit2junit.rb was written by Christian Hedin <[email protected]> 
# Version: 0.1 - 30/01 2010 
# Usage: 
# xcodebuild -yoursettings | ocunit2junit.rb 
# All output is just passed through to stdout so you don't miss a thing! 
# JUnit style XML-report are put in the folder specified below. 
# 
# Known problems: 
# * "Errors" are not cought, only "warnings". 
# * It's not possible to click links to failed test in Hudson 
# * It's not possible to browse the source code in Hudson 
# 
# Acknowledgement: 
# Big thanks to Steen Lehmann for prettifying this script. 
################################################################ 
# Edit these variables to match your system 
# 
# 
# Where to put the XML-files from your unit tests 
TEST_REPORTS_FOLDER = "test-reports" 
# 
# 
# Don't edit below this line 
################################################################ 

require 'time' 
require 'FileUtils' 
require 'socket' 

class ReportParser 

    attr_reader :exit_code 

    def initialize(piped_input) 
    @piped_input = piped_input 
    @exit_code = 0 

    FileUtils.rm_rf(TEST_REPORTS_FOLDER) 
    FileUtils.mkdir(TEST_REPORTS_FOLDER) 
    parse_input 
    end 

    private 

    def parse_input 
    @piped_input.each do |piped_row| 
     puts piped_row 
     case piped_row 

     when /Test Suite '(\S+)'.*started at\s+(.*)/ 
      t = Time.parse($2.to_s) 
      handle_start_test_suite(t) 

     when /Test Suite '(\S+)'.*finished at\s+(.*)./ 
      t = Time.parse($2.to_s) 
      handle_end_test_suite($1,t)  

     when /Test Case '-\[\S+\s+(\S+)\]' started./ 
      test_case = $1 

     when /Test Case '-\[\S+\s+(\S+)\]' passed \((.*) seconds\)/ 
      test_case = $1 
      test_case_duration = $2.to_f 
      handle_test_passed(test_case,test_case_duration) 

     when /(.*): error: -\[(\S+) (\S+)\] : (.*)/ 
      error_location = $1 
      test_suite = $2 
      test_case = $3 
      error_message = $4 
      handle_test_error(test_suite,test_case,error_message,error_location) 

     when /Test Case '-\[\S+ (\S+)\]' failed \((\S+) seconds\)/ 
      test_case = $1 
      test_case_duration = $2.to_f 
      handle_test_failed(test_case,test_case_duration) 

     when /failed with exit code (\d+)/ 
      @exit_code = $1.to_i 

     when 
      /BUILD FAILED/ 
      @exit_code = -1; 
     end 
    end 
    end 

    def handle_start_test_suite(start_time) 
    @total_failed_test_cases = 0 
    @total_passed_test_cases = 0 
    @tests_results = Hash.new # test_case -> duration 
    @errors = Hash.new # test_case -> error_msg 
    @ended_current_test_suite = false 
    @cur_start_time = start_time 
    end 

    def handle_end_test_suite(test_name,end_time) 
    unless @ended_current_test_suite 
     current_file = File.open("#{TEST_REPORTS_FOLDER}/TEST-#{test_name}.xml", 'w') 
     host_name = string_to_xml Socket.gethostname 
     test_name = string_to_xml test_name 
     test_duration = (end_time - @cur_start_time).to_s 
     total_tests = @total_failed_test_cases + @total_passed_test_cases 
     suite_info = '<testsuite errors="0" failures="'[email protected]_failed_test_cases.to_s+'" hostname="'+host_name+'" name="'+test_name+'" tests="'+total_tests.to_s+'" time="'+test_duration.to_s+'" timestamp="'+end_time.to_s+'">' 
     current_file << "<?xml version='1.0' encoding='UTF-8' ?>\n" 
     current_file << suite_info 
     @tests_results.each do |t| 
     test_case = string_to_xml t[0] 
     duration = @tests_results[test_case] 
     current_file << "<testcase classname='#{test_name}' name='#{test_case}' time='#{duration.to_s}'" 
     unless @errors[test_case].nil? 
      # uh oh we got a failure 
      puts "tests_errors[0]" 
      puts @errors[test_case][0] 
      puts "tests_errors[1]" 
      puts @errors[test_case][1] 

      message = string_to_xml @errors[test_case][0].to_s 
      location = string_to_xml @errors[test_case][1].to_s 
      current_file << ">\n" 
      current_file << "<failure message='#{message}' type='Failure'>#{location}</failure>\n" 
      current_file << "</testcase>\n" 
     else 
      current_file << " />\n" 
     end 
     end 
     current_file << "</testsuite>\n" 
     current_file.close 
     @ended_current_test_suite = true 
    end 
    end 

    def string_to_xml(s) 
    s.gsub(/&/, '&amp;').gsub(/'/, '&quot;').gsub(/</, '&lt;') 
    end 

    def handle_test_passed(test_case,test_case_duration) 
    @total_passed_test_cases += 1 
    @tests_results[test_case] = test_case_duration 
    end 

    def handle_test_error(test_suite,test_case,error_message,error_location) 
# error_message.tr!('<','').tr!('>','') 
    @errors[test_case] = [ error_message, error_location ] 
    end 

    def handle_test_failed(test_case,test_case_duration) 
    @total_failed_test_cases +=1 
    @tests_results[test_case] = test_case_duration 
    end 

end 

#Main 
#piped_input = File.open("tests_fail.txt") # for debugging this script 
piped_input = ARGF.read 

report = ReportParser.new(piped_input) 

exit report.exit_code 
+0

HI Martin, tôi đang sử dụng nó cho các bài kiểm tra OCUnit nhưng câu hỏi của tôi liên quan đến các bài kiểm tra UI mà tôi đang sử dụng Công cụ Tự động hóa Giao diện người dùng của Apple. Các thử nghiệm này được viết bằng javascript và tạo ra kết quả đầu ra XML. – MandyW

+0

@MandyW hooo, tôi rất tiếc vì tôi không nhận được câu hỏi của bạn đúng cách.Mã tôi cung cấp là để thay đổi các kiểm tra OCUnit thành Jenkins/Hudson không phải để thay đổi đầu ra của tập lệnh UIAutomation thành Jenkins/Hudson. Dù sao tôi hy vọng bạn tìm ra –

1

Có thể bạn có thể sử dụng this.

Và trong Jenkins thực thi shell:

sh setup.sh sh runTests.sh ./sample/alltests.js "/Users/komejun/Library/Application Support/iPhone Simulator/5.0/Applications/1622F505-8C07-47E0-B0F0-3A125A88B329/Recipes.app/" 

Và báo cáo sẽ được tự động tạo ra trong ./ynmsk-report/test.xml

+0

Xin chào, liên kết dường như đi đến một 404 .. – MandyW

+0

@MandyW địa chỉ có cheanged。https: //github.com/douban/ynm3k。 – houlianpi

0

Bạn có thể sử dụng thư viện tuneupjs. Thư viện cung cấp runner thử nghiệm tạo báo cáo xml (kiểu jUnit). Nó hoạt động với Xcode 6. Đối với báo cáo xml chỉ cung cấp -x param. Kiểm tra tại đây: http://www.tuneupjs.org/running.html

Các vấn đề liên quan