Xcode7.0 환경에서 덮어쓰기 보고서 내보내기

7158 단어 XcodeXcodeCoverage
지난번투고한 문장에는 서비스 범위를 확인할 수 있었지만 납품 등과 관련된 상황에서는 보고 형식으로 수출하고 싶었다.
이번에 마침 이런 사례를 만났으니 메모할 때 공유해 보자.
※ 본 기사는 2016년 02월 29일자 내용입니다.

운영 환경

  • OSX Yosemite 10.10.5
  • Xcode 7.2 (7C68)
  • CocoaPods 0.39.0
  • Homebrew 0.9.5
  • 대상 사례

  • CocoaPods를 통한 패키지 관리
  • 유닛 테스트 작성 중
  • HTML 출력으로 보고서 덮어쓰기
  • 도구 등을 이용하다

  • XcodeCoverage
  • lcov
  • gnu-sed
  • 대상 항목


    https://github.com/KenichiOkumura/CoverageReportSample.git
    이 프로젝트는 아래의 절차에 따라 제작되었다.
  • Wellcome to Xcode > Create a new Xcode project
  • iOS > Application > Single View Application
  • 각종 설정은 다음과 같다.

  • TargetClass.h TargetClass.m 추가 및 편집
  • CoverageReportSampleTests.m 편집
  • Project > CoverageReportSample > Generate Legacy Test Coverate Files > YES

  • Project > CoverageReportSample > Instrument Program Flow > YES

  • TARGETS > Build Phases > + > New Run Script Phase > Pods/XcodeCoverage/exportenv.sh

  • pod init>Podfile에 XcodeCoverage
  • 추가

    보고서 생성 프로세스


    1. Homebrew에 lcov 설치 및 경로 확인

    $ brew install lcov
    ==> Downloading https://homebrew.bintray.com/bottles/lcov-1.12.yosemite.bottle.tar.gz
    Already downloaded: /Library/Caches/Homebrew/lcov-1.12.yosemite.bottle.tar.gz
    ==> Pouring lcov-1.12.yosemite.bottle.tar.gz
    🍺  /usr/local/Cellar/lcov/1.12: 16 files, 533.3K
    
    $ which lcov
    /usr/local/bin/lcov
    
    $ lcov --version
    lcov: LCOV version 1.12
    

    2.pod install

    $ cd {PROJECT_ROOT}
    $ pod install
    Updating local specs repositories
    
    CocoaPods 1.0.0.beta.4 is available.
    To update use: `gem install cocoapods --pre`
    [!] This is a test version we'd love you to try.
    
    For more information see http://blog.cocoapods.org
    and the CHANGELOG for this version http://git.io/BaH8pQ.
    
    Analyzing dependencies
    Downloading dependencies
    Installing XcodeCoverage (1.2.2)
    Generating Pods project
    Integrating client project
    Sending stats
    Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
    

    3.envcov.sh의 내용을 brew가 설치한lcov 경로로 바꾸기


    CocoaPods에서 얻은 XcodeCoverage 내의 envcov.sh에 나열된 lcov 실행 경로를 Homebrew가 설치한 경로로 변경합니다.
    이 기사를 쓸 때의 envcov.sh에는 XcodeCoverage에 내장된lcov-1.11에서 실행해야 한다고 적혀 있지만 Xcode7 환경에서 실행이 잘 되지 않습니다참고 자료.
    $ cd {PROJECT_ROOT}
    $ vi Pods/XcodeCoverage/envcov.sh
    8 - LCOV_PATH="${scripts}/lcov-1.11/bin"
    8 + LCOV_PATH="/usr/local/bin/"
    

    4. 테스트 실행


    CoverageReportSample.xcworkspace를 열고 테스트를 실행합니다.
    * CoverageReportSample.xcworkspace 열기
    *CoverageReportSample> 적합한 에뮬레이터 선택 > 제품 > 테스트

    5. XcodeCoverage 수행


    CocoaPods에서 캡처한 XcodeCoverage에서 getcov를 실행합니다.
    $ cd {PROJECT_ROOT}
    $ ./Pods/XcodeCoverage/getcov --show -o ~/Desktop/
    Show HTML Report
    output_dir = /Users/user/Desktop/
    ~/Desktop ~/Desktop/CoverageReportSample
    ~/Desktop/CoverageReportSample
    Capturing coverage data from /Users/user/Library/Developer/Xcode/DerivedData/CoverageReportSample-clwbjkiwcxqjnnaikakwgjmwcgtc/Build/Intermediates/CoverageReportSample.build/Debug-iphonesimulator/CoverageReportSample.build/Objects-normal/x86_64
    Found gcov version: 7.0.2
    Found LLVM gcov version 3.4, which emulates gcov version 4.2
    Scanning /Users/user/Library/Developer/Xcode/DerivedData/CoverageReportSample-clwbjkiwcxqjnnaikakwgjmwcgtc/Build/Intermediates/CoverageReportSample.build/Debug-iphonesimulator/CoverageReportSample.build/Objects-normal/x86_64 for .gcda files ...
    Found 4 data files in /Users/user/Library/Developer/Xcode/DerivedData/CoverageReportSample-clwbjkiwcxqjnnaikakwgjmwcgtc/Build/Intermediates/CoverageReportSample.build/Debug-iphonesimulator/CoverageReportSample.build/Objects-normal/x86_64
    Processing x86_64/AppDelegate.gcda
    Processing x86_64/main.gcda
    Processing x86_64/TargetClass.gcda
    Processing x86_64/ViewController.gcda
    Finished .info-file creation
    Reading tracefile Coverage.info
    Deleted 0 files
    Writing data to Coverage.info
    Summary coverage rate:
      lines......: 64.0% (16 of 25 lines)
      functions..: 60.0% (9 of 15 functions)
      branches...: no data found
    Reading tracefile Coverage.info
    Removing /Users/user/Desktop/CoverageReportSample/CoverageReportSample/main.m
    Deleted 1 files
    Writing data to Coverage.info
    Summary coverage rate:
      lines......: 57.1% (12 of 21 lines)
      functions..: 57.1% (8 of 14 functions)
      branches...: no data found
    Reading data file Coverage.info
    Found 4 entries.
    Found common filename prefix "/Users/user/Desktop/CoverageReportSample"
    Writing .css and .png files.
    Generating output.
    Processing file CoverageReportSample/ViewController.m
    Processing file CoverageReportSample/TargetClass.m
    Processing file CoverageReportSample/AppDelegate.h
    Processing file CoverageReportSample/AppDelegate.m
    Writing directory view page.
    Overall coverage rate:
      lines......: 57.1% (12 of 21 lines)
      functions..: 57.1% (8 of 14 functions)
    

    후기


    결과는 이렇게 완성된 것이다.
    통과하지 못한 곳에는 빨간색이 표시되니 이해하기 쉬워요!

    또한 Pod에서 envcov를 고쳐 씁니다.sh는 당연한 일입니다. Pod이 업데이트되면 사라질 수 있습니다.
    자신이 힘들기 때문에gnu-sed로 바꾸는 스크립트를 만들었습니다.
    $ cd {PROJECT_ROOT}
    $ touch coverage.sh
    $ chmod +x coverage.sh
    $ vi coverage.sh
    #!/bin/bash
    
    # brewでlcoveとgnu-sedをインストール
    brew install lcove gnu-sed
    # brew でのインストール先確認
    # which lcov
    # envcov.shのlcov参照先をbrewへ向ける
    gsed -i '8c LCOV_PATH="/usr/local/bin/"' Pods/XcodeCoverage/envcov.sh
    # カバレッジレポートをデスクトップへ出力
    ./Pods/XcodeCoverage/getcov --show -o ~/Desktop/
    

    좋은 웹페이지 즐겨찾기