|
1 | 1 | 
|
2 | 2 |
|
3 |
| -These scripts provide a simple way to generate HTML reports of the code coverage |
4 |
| -of your Xcode project. |
| 3 | +These scripts provide a simple way to generate HTML reports of the code coverage of your Xcode project. |
5 | 4 |
|
6 | 5 |
|
7 |
| -Installation |
8 |
| -============ |
| 6 | +Xcode Project Setup |
| 7 | +=================== |
| 8 | + |
| 9 | +Before you get started, there are a couple of steps you will need to take to prepare your project: |
| 10 | + |
| 11 | +1. Depending on your version of Xcode, you may need to get Xcode's coverage instrumentation by going to Xcode > Preferences, into Downloads, and installing Command Line Tools. If you do not see this as an option in the Downloads section, the tools should already be installed. |
| 12 | +4. In your Xcode project, enable these two build settings at the project level for your Debug configuration only: |
| 13 | + * Instrument Program Flow |
| 14 | + * Generate Test Coverage Files |
| 15 | + |
9 | 16 |
|
10 |
| -1. Fork this repository; you're probably going to want to make your own |
11 |
| -modifications. |
| 17 | +Installation: Standard |
| 18 | +====================== |
| 19 | + |
| 20 | +1. Fork this repository; you're probably going to want to make your own modifications. |
12 | 21 | 2. Place the XcodeCoverage folder in the same folder as your Xcode project.
|
13 |
| -3. Depending on your version of Xcode, you may need to get Xcode's coverage |
14 |
| -instrumentation by going to Xcode Preferences, into Downloads, and installing |
15 |
| -Command Line Tools. |
16 |
| -4. In your Xcode project, enable these two build settings at the project level |
17 |
| -for your Debug configuration only: |
18 |
| - * Instrument Program Flow |
19 |
| - * Generate Test Coverage Files |
20 |
| -5. In your main target, add a Run Script build phase to execute |
21 |
| -``XcodeCoverage/exportenv.sh`` |
| 22 | +5. In your main target, add a Run Script build phase to execute `XcodeCoverage/exportenv.sh` |
| 23 | + |
| 24 | +A few people have been tripped up by the last step: Make sure you add the script to your main target (your app or library), not your test target. |
| 25 | + |
| 26 | + |
| 27 | +Installation: CocoaPods |
| 28 | +======================= |
22 | 29 |
|
23 |
| -A few people have been tripped up by the last step: Make sure you add the |
24 |
| -script to your main target (your app or library), not your test target. |
| 30 | +A [CocoaPod](http://cocoapods.org/) has been added for convenient use in simple projects. There are a couple of things you should be aware of if you are using the CocoaPod instead of the standard method: |
| 31 | + |
| 32 | +- There will be no actual files added to your project. Files are only added through `preserve_paths`, so they will be available in your `Pods/XcodeCoverage` path, but you will not see them in Xcode, and they will not be compiled by Xcode. |
| 33 | +- You will not be able to modify the scripts without those modifications being potentially overwritten by CocoaPods. |
| 34 | + |
| 35 | +If those caveats are deal-breakers, please use the standard installation method above. |
| 36 | + |
| 37 | +The steps to install via CocoaPods: |
| 38 | + |
| 39 | +1. Add `pod 'XcodeCoverage', '~>1.0'` (or whatever [version specification](http://guides.cocoapods.org/using/the-podfile.html#specifying-pod-versions) you desire) to your Podfile. |
| 40 | +2. Run `pod install`. This will download the necessary files. |
| 41 | +3. In your main target, add a Run Script build phase to execute |
| 42 | +`Pods/XcodeCoverage/exportenv.sh`. |
| 43 | + |
| 44 | +Again, make sure you add the script to your main target (your app or library), not your test target. |
25 | 45 |
|
26 | 46 |
|
27 | 47 | Execution
|
28 | 48 | =========
|
29 | 49 |
|
30 |
| -1. Run your unit tests |
| 50 | +Immediately after installation, run your application at least once to generate the `env.sh` file, which will be placed at the same level as your `.xcodeproj` folder. This file should *not* be checked into version control, since it contains paths local to your machine. |
| 51 | + |
| 52 | +Once that task has been completed, the process is very simple: |
| 53 | + |
| 54 | +1. Run your unit tests. |
31 | 55 | 2. In Terminal, execute `getcov` in your project's XcodeCoverage folder.
|
32 | 56 |
|
33 |
| -If you make changes to your test code without changing the production code and |
34 |
| -want a clean slate, use the ``cleancov`` script. |
| 57 | +If you make changes to your test code without changing the production code and want a clean slate, use the `cleancov` script. |
35 | 58 |
|
36 | 59 | If you make changes to your production code, you should clear out all build
|
37 |
| -artifacts before measuring code coverage again. "Clean Build Folder" by holding |
38 |
| -down the Option key in Xcode's "Product" menu. |
| 60 | +artifacts before measuring code coverage again. "Clean Build Folder" by holding down the Option key in Xcode's "Product" menu. |
39 | 61 |
|
40 | 62 | **Optional:** XcodeCoverage can prompt to run code coverage after running unit tests:
|
41 | 63 |
|
42 | 64 | * Edit Xcode scheme -> Test -> Post-actions
|
43 |
| - * Set "Shell" to: ``/bin/bash`` |
| 65 | + * Set "Shell" to: `/bin/bash` |
44 | 66 | * Set "Provide build settings from" to your main target
|
45 |
| - * Set script to: |
46 |
| - ``source ${SRCROOT}/XcodeCoverage/run_code_coverage_post.sh`` |
| 67 | + * Set script to: `source ${SRCROOT}/XcodeCoverage/run_code_coverage_post.sh` |
47 | 68 |
|
48 | 69 |
|
49 | 70 | Modification
|
50 | 71 | ============
|
51 | 72 |
|
52 |
| -There are two places you may want to modify: |
| 73 | +There are two places you may want to modify the included files if you are using the standard installation: |
53 | 74 |
|
54 |
| -1. In envcov.sh, ``LCOV_INFO`` determines the name shown in the report. |
55 |
| -2. In getcov, edit ``exclude_data()`` to specify which files to exclude, for |
56 |
| -example, third-party libraries. |
| 75 | +1. In `envcov.sh`, `LCOV_INFO` determines the name shown in the report. |
| 76 | +2. In `getcov`, edit `exclude_data()` to specify which files to exclude, for example, third-party libraries. |
0 commit comments