Code Monkey home page Code Monkey logo

ocunit2junit's Introduction

ABANDONWARE!

This script is no longer maintained! Have a look at one of the many forks or look for alternatives. Thanks for all the fish! ๐ŸŸ

Introduction

OCUnit2JUnit is a script that converts output from OCUnit or Kiwi to the format used by JUnit. The main purpose is to be able to parse output from Objective-C (OCUnit) test cases on a Java-based build server, such as Jenkins.

Installation

  • Install with 'gem install ocunit2junit' (possibly prepended by 'sudo' if your Ruby installation requires that)

Usage

  • Make sure your build server can access the xcodebuild executable

  • Use this shell command to build:

    xcodebuild -target <target> -sdk <sdk> -configuration <config> 2>&1 | ocunit2junit

  • The output is, by default, in the test-reports folder

  • If your build fails, this script will pass the error code

  • All output is also passed along, so you will still see everything in your build log

Kiwi

This script also generates human readable test results for Kiwi BDD Testing Framework:

Example output

However, if you don't want this, you can disable it in the header:

SUPPORT_KIWI = false

More information

  • If you're having issues with character encoding, please upgrade to Ruby 1.9.2 or later.
  • More info can be found in this blog post.

Licence

Free to use however you want.

Author

OCUnit2JUnit was created by Christian Hedin. Twitter: @ciryon Google Plus: https://plus.google.com/103286810504956788514/

ocunit2junit's People

Contributors

andrewsardone avatar ciryon avatar djx339 avatar e28eta avatar erwinskool avatar jonnolen avatar keithduncan avatar lowammo avatar marklarr avatar yiyuanlu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ocunit2junit's Issues

ruby 1.92 bug

/Users/xxx/.rvm/gems/ruby-1.9.2-p290/gems/ocunit2junit-1.3/bin/ocunit2junit:50:in encode!': code converter not found (UTF-8 to UTF-16) (Encoding::ConverterNotFoundError) from /Users/xxx/.rvm/gems/ruby-1.9.2-p290/gems/ocunit2junit-1.3/bin/ocunit2junit:50:inblock in parse_input'
from /Users/xxx/.rvm/gems/ruby-1.9.2-p290/gems/ocunit2junit-1.3/bin/ocunit2junit:49:in each' from /Users/xxx/.rvm/gems/ruby-1.9.2-p290/gems/ocunit2junit-1.3/bin/ocunit2junit:49:inparse_input'
from /Users/xxx/.rvm/gems/ruby-1.9.2-p290/gems/ocunit2junit-1.3/bin/ocunit2junit:43:in initialize' from /Users/xxx/.rvm/gems/ruby-1.9.2-p290/gems/ocunit2junit-1.3/bin/ocunit2junit:183:innew'
from /Users/xxx/.rvm/gems/ruby-1.9.2-p290/gems/ocunit2junit-1.3/bin/ocunit2junit:183:in <top (required)>' from /Users/xxx/.rvm/gems/ruby-1.9.2-p290/bin/ocunit2junit:19:inload'
from /Users/xxx/.rvm/gems/ruby-1.9.2-p290/bin/ocunit2junit:19:in `

'

xml file not getting generated

Have given below command
xcodebuild -workspace Sample.xcworkspace -scheme "SampleUITestsShared" -derivedDataPath Build/ -destination 'platform=iOS Simulator,OS=12.4,name=iPhone Xs' -enableCodeCoverage YES clean build test | ocunit2junit

test-reports folder got generated but xml file is not there

Xcode version is 10.3

All my test cases passed and in terminal Xcode output is shown and xcovreport got generated.

Xcode 6 beta4 issue

Hi,

It might be early but it seems ocunit2junit does not understand correctly test outputs when run with xcode6 beta4. For example the output below will not yield any xml reports :

** TEST SUCCEEDED **

Test Suite 'All tests' started at 2014-08-01 14:35:24 +0000
Test Suite 'Mobile Daily Test ProjectTests.xctest' started at 2014-08-01 14:35:24 +0000
Test Suite 'SomeTests' started at 2014-08-01 14:35:24 +0000
Test Case '-[SomeTests testExample]' started.
Test Case '-[SomeTests testExample]' passed (0.003 seconds).
Test Suite 'SomeTests' passed at 2014-08-01 14:35:24 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 0.003 (0.004) seconds
Test Suite 'Moile_Daily_Test_ProjectTests' started at 2014-08-01 14:35:24 +0000
Test Case '-[Moile_Daily_Test_ProjectTests testExample]' started.
Test Case '-[Moile_Daily_Test_ProjectTests testExample]' passed (0.002 seconds).
Test Suite 'Moile_Daily_Test_ProjectTests' passed at 2014-08-01 14:35:24 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 0.002 (0.002) seconds
Test Suite 'Mobile Daily Test ProjectTests.xctest' passed at 2014-08-01 14:35:24 +0000.
Executed 2 tests, with 0 failures (0 unexpected) in 0.005 (0.008) seconds
Test Suite 'All tests' passed at 2014-08-01 14:35:24 +0000.
Executed 2 tests, with 0 failures (0 unexpected) in 0.005 (0.010) seconds

While it works with the output from xcode5:

Test Suite 'All tests' started at 2014-08-01 15:08:14 +0000
Test Suite 'Mobile Daily Test ProjectTests.xctest' started at 2014-08-01 15:08:14 +0000
Test Suite 'SomeTests' started at 2014-08-01 15:08:14 +0000
Test Case '-[SomeTests testExample]' started.
Test Case '-[SomeTests testExample]' passed (0.001 seconds).
Test Suite 'SomeTests' finished at 2014-08-01 15:08:14 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'Moile_Daily_Test_ProjectTests' started at 2014-08-01 15:08:14 +0000
Test Case '-[Moile_Daily_Test_ProjectTests testExample]' started.
Test Case '-[Moile_Daily_Test_ProjectTests testExample]' passed (0.002 seconds).
Test Suite 'Moile_Daily_Test_ProjectTests' finished at 2014-08-01 15:08:14 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 0.002 (0.002) seconds
Test Suite 'Mobile Daily Test ProjectTests.xctest' finished at 2014-08-01 15:08:14 +0000.
Executed 2 tests, with 0 failures (0 unexpected) in 0.003 (0.003) seconds
Test Suite 'All tests' finished at 2014-08-01 15:08:14 +0000.
Executed 2 tests, with 0 failures (0 unexpected) in 0.003 (0.005) seconds
** TEST SUCCEEDED **

.xml files not found in test-reports

I have run this command both in console and in jenkins
xcodebuild -target GuildBrowserLogicTests -sdk iphonesimulator -configuration Debug clean build | /usr/local/bin/ocunit2junit

but there is nothing in test-reports folder. In console the output ends at ** BUILD SUCCEEDED **.

Any idea?

Error when handling nil values in handle_end_test_suite

We keep running into the following error sporadically in our build.
17:02:38 /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:160:in `-': nil can't be coerced into Fixnum (TypeError) 17:02:38 from /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:160:in `handle_end_test_suite' 17:02:38 from /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:99:in `block in parse_input' 17:02:38 from /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:55:in `each' 17:02:38 from /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:55:in `each' 17:02:38 from /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:55:in `parse_input' 17:02:38 from /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:43:in `initialize' 17:02:38 from /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:236:in `new' 17:02:38 from /usr/local/lib/ruby/gems/2.3.0/gems/ocunit2junit-1.4/bin/ocunit2junit:236:in `<top (required)>' 17:02:38 from /usr/local/bin/ocunit2junit:23:in `load' 17:02:38 from /usr/local/bin/ocunit2junit:23:in `<main>'

It happens when end_time is nil in handle_end_test_suite.
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

We have tried to resolve this by adding a if statement before the arithmetic operation.
end_time=0 if end_time.nil?

will this work or break something else?

Test Case output not visible in JUnit

Capture test case output.
Please, note how JUnit is capturing test case output into a <system-out> tag with CDATA contents. It would be nice if OCUnit2JUnit were capturing the output, too.

Kiwi test results not parsing correctly

I'm using Kiwi in my test suite. When I run it through ocunit2junit, I get xml entries like this

<testcase classname='SomeRedactedTest' name=SomeRedactedTest_RedactedOuterContext_RedactedInnerContext_RedactedItShould' time='0.001' />

I wonder if this is because I have nested contexts? I see there are some regex doing some work in the ruby code, but I can't quite figure it out.

EDIT: Looks like it's happening without the outer context, too.

String 'each' method is deprecated since Ruby 1.9

When trying to run the script with Ruby 2.0.0, a NoMethodError is thrown:

parse_input': undefined methodeach' for #String:0x007fbe0206dae8 (NoMethodError)

Line 49:

@piped_input.each do |piped_row|

should be

@piped_input.each_line do |piped_row|

NoMethodError 'encode' in ruby 1.8.7

I am trying to run xcodebuild command and append ocunit2junit with it to get the report output.
When i run it, i see following error:

/Library/Ruby/Gems/1.8/gems/ocunit2junit-1.3/bin/ocunit2junit:50:in parse_input': undefined methodencode!' for "Build settings from command line:\n":String (NoMethodError)
from /Library/Ruby/Gems/1.8/gems/ocunit2junit-1.3/bin/ocunit2junit:49:in each' from /Library/Ruby/Gems/1.8/gems/ocunit2junit-1.3/bin/ocunit2junit:49:inparse_input'
from /Library/Ruby/Gems/1.8/gems/ocunit2junit-1.3/bin/ocunit2junit:43:in initialize' from /Library/Ruby/Gems/1.8/gems/ocunit2junit-1.3/bin/ocunit2junit:183:innew'
from /Library/Ruby/Gems/1.8/gems/ocunit2junit-1.3/bin/ocunit2junit:183
from /usr/bin/ocunit2junit:19:in `load'
from /usr/bin/ocunit2junit:19

Need a solution for this, which i can't find anywhere. Please help !

Provide a ruby gem

Hi,

can you provide a gem spec and publish your project to the rubygems.org repo?

That would be nice.

Thanks. :-)

Does not handle Test Suite names with spaces

I'm having trouble with one of my projects, because it has a test suite with a space in the name.

Here's an example of the relevant output:

[DEBUG] Test Suite 'All tests' started at 2013-06-18 00:59:57 +0000
Test Suite '/Users/e28eta/source/MyApp/build/Ad Hoc-iphonesimulator/MyAppTests.octest(Tests)' started at 2013-06-18 00:59:57 +0000
Test Suite 'MyApp Tests' started at 2013-06-18 00:59:57 +0000
Test Case '-[MyAppTest someTestCase]' started.

Results in the following error:

/Users/e28eta/bin/ocunit2junit.rb:158:in `handle_test_passed': undefined method `+' for nil:NilClass (NoMethodError)
    from /Users/e28eta/bin/ocunit2junit.rb:80:in `parse_input'
    from /Users/e28eta/bin/ocunit2junit.rb:50:in `each'
    from /Users/e28eta/bin/ocunit2junit.rb:50:in `parse_input'
    from /Users/e28eta/bin/ocunit2junit.rb:44:in `initialize'
    from /Users/e28eta/bin/ocunit2junit.rb:186:in `new'
    from /Users/e28eta/bin/ocunit2junit.rb:186

It dies on @total_passed_test_cases += 1 because:

  • handle_start_test_suite was never called, because the Test Suite name regex doesn't accept spaces
  • and, all three of the initial Test Suite lines in my output have a space.

The reason I have a space in 'MyApp Tests' is because we're manually setting up a suite:

SenTestSuite *suite = [SenTestSuite testSuiteWithName:@"MyApp Tests"];

So it looks like I can work around it (remove the space). However, it'd be nice if that wasn't necessary.

I'm too unfamiliar with OCUnit's output to know whether it's safe to simply change the Test Suite regex to something like this:

when /Test Suite '([^']+)'.*started at\s+(.*)/

or if that would break something else. Do you know?

Syntax Error - running OS X Mountain Lion and Ruby 1.8.7

Apologies if this a known or non-issue but I'm not familiar with Ruby so I don't really know what the problem is.

I'm basically trying to get ocunit2junit running within our build process on our build server. Piping xcodebuild into ocunit2junit works fine on my local machine but on the build server is gives me the following error:
ocunit2junit:185: syntax error, unexpected '.', expecting kEND
.gsub(/([A-Z][a-z]+)/, ' \1')
^
ocunit2junit:186: syntax error, unexpected '.', expecting kEND
.gsub(/([A-Z][A-Z]+)/, ' \1')
^
ocunit2junit:187: syntax error, unexpected '.', expecting kEND
.gsub(/([^A-Za-z ]+)/, ' \1')
^
ocunit2junit:188: syntax error, unexpected '.', expecting kEND
.gsub(/\s+/, ' ')
^
ocunit2junit:189: syntax error, unexpected '.', expecting kEND
.split(" _ ")[1..-1].join(", ")
^
ocunit2junit:190: syntax error, unexpected '.', expecting kEND
.downcase.capitalize
^

Which I believe relates to the elsif in this function:
def get_test_case_name(test_case, description)
# Kiwi 1.x
if SUPPORT_KIWI && test_case == "example" && description
description
# Kiwi 2.x
elsif SUPPORT_KIWI && test_case =~ /(.+)+(Should.+)(.+)*/
test_case.gsub(/([A-Z])([A-Z][a-z]+)/, ' \1 \2')
.gsub(/([A-Z][a-z]+)/, ' \1')
.gsub(/([A-Z][A-Z]+)/, ' \1')
.gsub(/([^A-Za-z ]+)/, ' \1')
.gsub(/\s+/, ' ')
.split(" _ ")[1..-1].join(", ")
.downcase.capitalize
else
test_case
end

Do you have any ideas as to why I'm having this problem?

Thanks a lot,

Tom

Performance tests time taken is wrong

In this case it's a benchmark test.

It should report that it took 0.316s
not 3.607 for the whole test

where 0.316 seconds is the average time for 10 passes
this is a feature of the new XCTest framework with

measureBlock{ () -> Void in
}

Results output:

Test Case '-[RTiOSSDK_UnitTestsTests.GeometryEnginePerformanceTests testBenchmarkWithinOnSmallPolygon]' started.
<unknown>:0: Test Case '-[RTiOSSDK_UnitTestsTests.GeometryEnginePerformanceTests testBenchmarkWithinOnSmallPolygon]' measured [Time, seconds] average: 0.316, relative standard deviation: 0.759%, values: [0.320914, 0.317904, 0.316536, 0.314073, 0.318229, 0.313852, 0.313627, 0.319198, 0.314853, 0.315057], performanceMetricID:com.apple.XCTPerformanceMetric_WallClockTime, baselineName: "", baselineAverage: , maxPercentRegression: 10.000%, maxPercentRelativeStandardDeviation: 10.000%, maxRegression: 0.100, maxStandardDeviation: 0.100
Test Case '-[RTiOSSDK_UnitTestsTests.GeometryEnginePerformanceTests testBenchmarkWithinOnSmallPolygon]' passed (3.607 seconds).

Support for pending tests

Hi,

I am using OCUnit2JUnit to get a report for Jenkins using Kiwi, and I see all my pending as passed. What about the feasibility of supporting pending tests here?

Thanks for any input

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.