You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These scripts provide a simple way to generate HTML reports of the code coverage of your Xcode project.
3
+
XcodeCoverage provides a simple way to generate reports of the code coverage of your Xcode project. Generated reports include HTML and Cobertura XML.
4
4
5
-
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
5
+
Coverage data excludes Apple's SDKs, and the exclusion rules can be customized.
15
6
16
7
17
8
Installation: Standard
18
9
======================
19
10
20
-
1. Fork this repository; you're probably going to want to make your own modifications.
11
+
Use the standard installation if you want to customize XcodeCoverage to exclude certain files and directories, such as third-party libraries. Otherwise, the CocoaPods installation described below may be more convenient.
12
+
13
+
1. Fork this repository.
21
14
2. Place the XcodeCoverage folder in the same folder as your Xcode project.
22
-
5. In your main target, add a Run Script build phase to execute `XcodeCoverage/exportenv.sh`
15
+
3. In your main target, add a Run Script build phase to execute `XcodeCoverage/exportenv.sh`
23
16
24
17
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
18
@@ -44,16 +37,38 @@ The steps to install via CocoaPods:
44
37
Again, make sure you add the script to your main target (your app or library), not your test target.
45
38
46
39
47
-
Execution
48
-
=========
40
+
Xcode Project Setup
41
+
===================
42
+
43
+
XcodeCoverage comes with an xcconfig file with the build settings required to instrument your code for coverage analysis.
44
+
45
+
If you already use an xcconfig, include it in the configuration you want to instrument:
46
+
* Standard installation: `#include "XcodeCoverage/XcodeCoverage.xcconfig"`
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.
49
+
If you don't already use an xcconfig, drag XcodeCoverage.xcconfig into your project. Where it prompts "Add to targets," deselect all targets. (Otherwise, it will be included in the bundle.) Then click on your project in Xcode's Navigator pane, and select the Info tab. For the configuration you want to instrument, select XcodeCoverage.
51
50
52
-
Once that task has been completed, the process is very simple:
51
+
If you'd rather specify the build settings by hand, enable these two settings at the project level:
52
+
* Instrument Program Flow
53
+
* Generate Test Coverage Files
54
+
55
+
Make sure not to instrument your AppStore release.
56
+
57
+
Execution
58
+
=========
53
59
54
60
1. Run your unit tests.
55
61
2. In Terminal, execute `getcov` in your project's XcodeCoverage folder.
56
62
63
+
`getcov` has the following command-line options:
64
+
65
+
*`--show` or `-s`: Show HTML report.
66
+
*`--xml` or `-x`: Generate Cobertura XML.
67
+
*`-o output_dir`: Specify output directory.
68
+
*`-i info_file`: Specify name of generated lcov info file.
69
+
*`-v`: Enable verbose output.
70
+
*`-h` or `--help`: Show usage.
71
+
57
72
If you make changes to your test code without changing the production code and want a clean slate, use the `cleancov` script.
58
73
59
74
If you make changes to your production code, you should clear out all build artifacts before measuring code coverage again. "Clean Build Folder" by holding down the Option key in Xcode's "Product" menu, or by using the ⌥⇧⌘K key combination.
@@ -63,16 +78,14 @@ If you make changes to your production code, you should clear out all build arti
63
78
* Edit Xcode scheme -> Test -> Post-actions
64
79
* Set "Shell" to: `/bin/bash`
65
80
* Set "Provide build settings from" to your main target
66
-
* Set script to:`source ${SRCROOT}/XcodeCoverage/run_code_coverage_post.sh`
81
+
* Set script to `source XcodeCoverage/run_code_coverage_post.sh` for standard installation. For CocoaPods installation, use `source Pods/XcodeCoverage/run_code_coverage_post.sh`
67
82
68
83
69
84
Modification
70
85
============
71
86
72
-
There are two places you may want to modify the included files if you are using the standard installation:
87
+
If you are using the standard installation, you can modify `exclude_data()` in `getcov` to specify which files to exclude, such as third-party libraries.
73
88
74
-
1. In `envcov.sh`, `LCOV_INFO` determines the name shown in the report.
75
-
2. In `getcov`, edit `exclude_data()` to specify which files to exclude, for example, third-party libraries.
0 commit comments