Last active
August 29, 2015 14:02
-
-
Save nking/0344e99ef25c2ec38021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generating Coverage Reports with Xcode 5.1.1 | |
If you need to test using the IOS 6.x simulator due to | |
testing in-app purchases, for example, you won't be able to use | |
the new XCTest library as those are IOS >= 7. The apple store | |
(simulator) is only available in the IOS 6.x simulators. | |
The notes below use GTM UnitTesting which are extensions | |
of SenTestingKit instead of XCTest. | |
This is an example of targets built for an older Xcode project that | |
I keep adapting to the newer IDE builds. There are many ways | |
to build your testing targets, so this is just one working | |
example. | |
The main target is the source target and is built using defaults | |
provided by the Xcode IDE. | |
The testing target is duplicate of the source target. You have | |
to remove main.m from "Build Phases" "Compile Sources". | |
Then to include GTM testing for GTMTestCases, | |
I used the older configuration instructions still present in their wiki, | |
but you should be able to use the simpler instructions at | |
the top of the page. | |
http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting#Older:_GTM_Unit_Testing_without_Apple's_support/Xcode_integ | |
(1) configure XCode 5.1.1 to generate gcno files | |
https://developer.apple.com/library/ios/qa/qa1514/_index.html | |
(2) then to generate gcda files from your GTMTestCase unit tests | |
you can either add to each unit test source file | |
extern void __gcov_flush(); | |
and a __gcov_flush(); to the tearDown method, | |
or you can add a few files from the google-toolbox-for-mac | |
(which adds a listener to do invoke __gcov_flush()) and a | |
pre-processer macro to include the code. | |
Instructions for the later are at: | |
https://code.google.com/p/coverstory/wiki/UsingCoverstory | |
To generatee reports for the gcda files: | |
you can use CoverStory.app, but there is a problem if your code uses | |
block variables or block arguments to functions, such as is common | |
with NSOperationQueue. | |
For _blocks there are errors such as ".gcno no lines for '__copy_helper_block_'" | |
and ".gcno:no lines for '__destroy_helper_block_'". | |
This might be due a mix of gcc and clang tools producing and expecting different names. | |
So the alternative is to use 2 more tools: | |
(3) use llvm-gov to generate each gcov file (gcov file is a readable ascii text | |
file of the source code with left edge markings for covered and not for each line of code) | |
/Library/Developer/CommandLineTools/usr/bin/llvm-cov -a -o gcda_directory a_gcda_file_path | |
(4) use lcov to create html files from the gcov files | |
http://ltp.sourceforge.net/coverage/lcov.php | |
lcov -t 'report_title' -o gcov.info -c -d gcov_directory | |
genhtml -o output_dir gcov.info | |
More details if needed: | |
After varying the coverage configuration, these are the build settings I now use: | |
Source target: | |
Generate test coverage files: YES for debug and debug device. NO for release | |
Instrument program flow: YES for debug and debug device. NO for release | |
Preprocessor Macros: GTM_IS_COVERAGE_BUILD=1 for debug | |
Other C Flags: -DDEBUG | |
Test target: | |
Generate test coverage files: YES for debug and debug device. NO for release | |
Instrument program flow: YES for debug and debug device. NO for release | |
My unit test files include the extern void __gcov_flush(), and then a __gcov_flush() | |
in the tearDown method because I'd already done that before finding the above. | |
There's room to simplify these instructions and the files included, but I haven't | |
take the time to do that yet. This working configuration might be helpful if | |
you're testing with IOS 6. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this - just now seeing your comment. If gist has notifications, I must not have it configured to on.