소스 검색

Tests: Add code coverage

Add MobileVLCKit Testscheme for code coverage
Add Gemfilea and  rake task for MobileVLCKit code coverage
Add MobileVLCKit code coverage task on CircleCI
Mike JS. Choi 7 년 전
부모
커밋
53dfdb4b4e
5개의 변경된 파일121개의 추가작업 그리고 6개의 파일을 삭제
  1. 14 0
      .circleci/config.yml
  2. 3 0
      Gemfile
  3. 15 0
      Gemfile.lock
  4. 57 0
      MobileVLCKit.xcodeproj/xcshareddata/xcschemes/MobileVLCKitTests.xcscheme
  5. 32 6
      Rakefile

+ 14 - 0
.circleci/config.yml

@@ -12,6 +12,13 @@ jobs:
     steps:
       - checkout
       - restore_cache:
+          key: v1-gems-{{ checksum "Gemfile.lock" }}
+      - run: bundle check || bundle install --path .bundle
+      - save_cache:
+          key: v1-gems-{{ checksum "Gemfile.lock" }}
+          paths:
+            - .bundle
+      - restore_cache:
           key: libvlc-{{ checksum "compileAndBuildVLCKit.sh" }}
       - run:
           name: Build VLCKit
@@ -27,4 +34,11 @@ jobs:
           name: Run Tests
           command: |
             rake test:ios
+      - run:
+          name: Generate Coverage Reports
+          command: |
+            rake codecov:ios
+      - store_artifacts:
+          path: Tests/Coverage
+          destination: Coverage
 

+ 3 - 0
Gemfile

@@ -0,0 +1,3 @@
+source "https://rubygems.org"
+
+gem "xcpretty"

+ 15 - 0
Gemfile.lock

@@ -0,0 +1,15 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    rouge (2.0.7)
+    xcpretty (0.2.8)
+      rouge (~> 2.0.7)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  xcpretty
+
+BUNDLED WITH
+   1.16.2

+ 57 - 0
MobileVLCKit.xcodeproj/xcshareddata/xcschemes/MobileVLCKitTests.xcscheme

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0930"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      codeCoverageEnabled = "YES"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+         <TestableReference
+            skipped = "NO">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "CA0301CA20ADFD2500452BB8"
+               BuildableName = "MobileVLCKitTests.xctest"
+               BlueprintName = "MobileVLCKitTests"
+               ReferencedContainer = "container:MobileVLCKit.xcodeproj">
+            </BuildableReference>
+         </TestableReference>
+      </Testables>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 32 - 6
Rakefile

@@ -21,19 +21,26 @@
 #
 # ------------------------------------------------------------- Constants ------
 
-SDK_SIM = 'iphonesimulator11.3'
-SDK_SIM_DEST = "'platform=iOS Simulator,name=iPhone 7,OS=11.3'"
+PROJECT_MOBILE = 'MobileVLCKit.xcodeproj'
+
+SDK_SIM_IOS = 'iphonesimulator11.3'
+
+SDK_SIM_DEST_IOS = "'platform=iOS Simulator,name=iPhone 7,OS=11.3'"
 
 SCHEME_IOS = 'MobileVLCKitTests'
-PROJECT_IOS = 'MobileVLCKit.xcodeproj'
 
 VLC_FLAGS_IOS = '-dva x86_64'
 
+DERIVED_DATA_PATH = 'DerivedData'
+COVERAGE_REPORT_PATH = 'Tests/Coverage'
+
+XCPRETTY = "xcpretty && exit ${PIPESTATUS[0]}"
+
 # ----------------------------------------------------------------- Tasks ------
 
-desc 'Build VLCKit (iOS)'
+desc 'Build MobileVLCKit'
 task 'build:vlckit:ios' do
-  puts 'Building VLCKit (iOS)'
+  puts 'Building MobileVLCKit'
 
   plugin_file = 'Resources/MobileVLCKit/vlc-plugins-iPhone.h'
   required_dirs = ['./libvlc/vlc/install-iPhoneSimulator', './libvlc/vlc/build-iPhoneSimulator']
@@ -48,11 +55,30 @@ end
 desc 'Run MobileVLCKit tests'
 task 'test:ios' do
   puts 'Running tests for MobileVLCKit'
-  sh "xcodebuild -project #{PROJECT_IOS} -scheme #{SCHEME_IOS} -sdk #{SDK_SIM} -destination #{SDK_SIM_DEST} test"
+  sh "xcodebuild -derivedDataPath #{DERIVED_DATA_PATH}/#{SCHEME_IOS} -project #{PROJECT_MOBILE} -scheme #{SCHEME_IOS} -sdk #{SDK_SIM_IOS} -destination #{SDK_SIM_DEST_IOS} test | #{XCPRETTY}"
+end
+
+desc 'Generate code coverage reports (MobileVLCKit)'
+task 'codecov:ios' do
+  puts 'Generating code coverage reports (MobileVLCKit)'
+  generate_coverage(SCHEME_IOS)
 end
 
 # ------------------------------------------------------------- Functions ------
 
+def generate_coverage(scheme)
+  report_name = "#{COVERAGE_REPORT_PATH}/#{scheme}_coverage.txt"
+  scheme_derived_data = "#{DERIVED_DATA_PATH}/#{scheme}"
+
+  if Dir.exist?(scheme_derived_data)
+    sh "mkdir -p #{COVERAGE_REPORT_PATH}"
+    sh "xcrun xccov view #{scheme_derived_data}/Logs/Test/*.xccovreport > #{report_name}"
+    sh "cat #{report_name}"
+  else
+    puts "#{scheme} has not been tested yet. Please run its tests first"
+  end
+end
+
 def dirs_exist?(directories)
   directories.each do |dir|
     return false unless Dir.exist?(dir)