Cocoapods: How generate code coverage report for Sonar for Cocoapod library?

Created on 19 Jun 2019  Â·  7Comments  Â·  Source: CocoaPods/CocoaPods

Report

Hi everyone.

We are currently developing an iOS app, with multiple functional modules as cocoapod libraries. The modules are projects that compile separate from the app, and they are linked as cocoapod dependency in the application. We are developing unit tests with XCTest and we want upload test coverage to a Sonar Swift project. We have a sonar proyect per module and per application.

Here is the problem, because there is not guide about how to generate coverage report for a cocoapod library to Sonar. ¿There is a way to doing this with cocoapod? ¿There is a way to generate coverage reports in the pod lib lint process?

We run the "pod lib lint" in modules, runing unit test perfectly. But not coverage data generated.

Any help is appreciated

Cheers

What did you do?

ℹ Run pod lib lint

What did you expect to happen?

Generate coverage data like *.xccovarchive files to translate and upload to Sonar Swift project

What happened instead?

No coverage data generated.

CocoaPods Environment

Stack

   CocoaPods : 1.6.0
        Ruby : ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
    RubyGems : 2.5.2.3
        Host : Mac OS X 10.14.5 (18F132)
       Xcode : 10.2.1 (10E1001)
         Git : git version 2.19.2
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 19a3cd7c43acecddf9adfd79b47293ca176a3564
               company-specs - [email protected]:core-mobile/ios/specs.git @ sdsdf

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-deintegrate : 1.0.2
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.3.1
cocoapods-try         : 1.1.0

Podfile

# Cocoa repositories list
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_modular_headers!

target 'Core' do
    # Third party libraries
    pod 'Alamofire', '4.8.2'
    # Auth0
    pod 'Auth0', '1.15'
    pod 'JWTDecode', '2.3.0'
    # Split.io
    pod 'Split', '2.3.0'
    # Google dependencies
    pod 'Firebase', '6.2.0'
    pod 'Firebase/Messaging', '6.2.0'
    pod 'Firebase/MLVision', '6.2.0'
    pod 'Firebase/MLVisionLabelModel', '6.2.0' 
    pod 'Firebase/MLVisionBarcodeModel', '6.2.0'
    pod 'Firebase/Core', '6.2.0'
    pod 'Crashlytics',  '3.13.1'
    pod 'Fabric', '1.10.1'
    pod 'GoogleTagManager', '7.1.2'
    # Checkeo que de conexion a red
    pod 'ReachabilitySwift', '4.3.1'
    # Notificaciones push
    pod 'AWSCore', '2.9.9'
end
moderate enhancement question

All 7 comments

Hi there, thanks for asking. I do not think there is a way to generate code coverage today. Are you using test specs? What is the podspec you are working with?

If you are using test specs then we could extend the scheme DSL to add support for code coverage generation maybe.

Marking as an enhancement

Hi D. Thanks for response!

Yes, we are using test specs. The podspec structure we are using in our libs are like this:

Pod::Spec.new do |s|

# 1
s.platform = :ios
s.ios.deployment_target = '10.0'
s.name = "Core"
s.summary = "Core module."
s.requires_arc = true
s.static_framework = true

# 2 
s.version = "0.14.0-beta"

# 3
s.license = { :type => "MIT", :file => "LICENSE" }

# 4 - Replace with your name and e-mail address
s.author = { "Facundo Rodriguez" => "[email protected]" }

# 5 - Replace this URL with your own GitHub page's URL (from the address bar)
s.homepage = "https://abc/core"

# 6 - Replace this URL with your own Git URL
s.source = { :git => "git@abc/ios/core.git",
:tag => "#{s.version}" }

# 7
s.framework = "UIKit"
s.dependency 'Alamofire', '4.8.2'

# Auth0
s.dependency 'Auth0', '1.15'
s.dependency 'JWTDecode', '2.3.0'

# Google
s.dependency 'Firebase', '6.2.0'
s.dependency 'Firebase/Core', '6.2.0'
s.dependency 'Firebase/MLVision', '6.2.0'
s.dependency 'Firebase/MLVisionLabelModel', '6.2.0' 
s.dependency 'Firebase/MLVisionBarcodeModel', '6.2.0'
s.dependency 'Firebase/Messaging', '6.2.0'
s.dependency 'GoogleUtilities', '6.2.0'

s.dependency 'Crashlytics', '3.13.1'
s.dependency 'Fabric', '1.10.1'
s.dependency 'GoogleTagManager', '7.1.2'

# Split.io - Cutpoint
s.dependency 'Split', '2.3.0'

# Manejo de errores
s.dependency 'ReachabilitySwift', '4.3.1'

# Notificaciones push
s.dependency 'AWSCore', '2.9.9'

# 8
s.source_files = "Core/**/*.{swift}"

# 9
#s.resources = "Core/**/*.{storyboard}"

# Test configuration
**s.test_spec 'Tests' do |test_spec|
test_spec.dependency 'Mockingjay', '2.0.1'
test_spec.framework = 'XCTest'
test_spec.source_files = 'Tests/**/*.{h,m,swift,plist}'
end**

# 10
s.swift_version = "4.2"

end

In the Tests folder we put all test clasess with XCTest and Mockinjay code. We run testcases allways for CI / CD with pod lib lint and pod repo push over Bitrise. But for code quality and CI, the code coverage and tests statistics are very important.
We are using Sonarqube wifth Sonar Swift
https://docs.sonarqube.org/display/PLUG/SonarSwift. There is a way to upload the coverage generated for an a Swift App, executing a scripts series. https://docs.sonarqube.org/display/PLUG/Swift+Coverage+Results+Import but not work with cocoapod libs.

If an enhacement is posible, we will very glad!

Thanks again! We are in touch

Cheers

Yes this will need to be an enhancement in order to extend scheme DSL to support setting code coverage flag to true

Great!

¿Do you think this enhancement will be choiced for implementation? ¿When you think this enhancement will be ready D.?

Thanks a lot!

The fastest way to implement it is to attempt to do it! I cannot guarantee personally any specific time this can be released.

Marking for 1.9.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pronebird picture pronebird  Â·  3Comments

k06a picture k06a  Â·  3Comments

marzapower picture marzapower  Â·  3Comments

luhui picture luhui  Â·  3Comments

soleares picture soleares  Â·  3Comments