Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to see Code Coverage in Xcode 4.2
    primarykey
    data
    text
    <p>I'm creating an iPhone 5.0 project in Xcode 4.2 and would like to find the code coverage when the unit tests are executed. I'm quite new to the Xcode environment, and I've followed the steps provided <a href="http://www.infinite-loop.dk/blog/2011/12/code-coverage-with-xcode-4-2/" rel="nofollow noreferrer">here</a>. I'm able to modify the Build Settings for the test target correctly, and link the "libprofile_rt.dylib" file fine. </p> <p>At this point, when I execute the tests (using Command-U), the code compiles and the tests pass. I do not encounter the problem described <a href="https://stackoverflow.com/questions/7776696/xcode-4-2-code-coverage">here</a>. In addition, I've installed <a href="http://code.google.com/p/coverstory/wiki/UsingCoverstory" rel="nofollow noreferrer">CoverStory</a>.</p> <p>The author in the first link mentions <a href="http://www.infinite-loop.dk/blog/2011/05/covering-it-all-up/" rel="nofollow noreferrer">"Just run your unit tests and view the code coverage data as usual"</a>; however, I cannot find <code>.../Objects-normal/i386</code>. </p> <p>Just to get things working, I created a new project with the following class: </p> <pre><code>#import "SomeClass.h" @implementation SomeClass @synthesize someValue; -(void)performWork:(BOOL)now withValue:(int)value { if (now) { someValue = value; } else { someValue = value - 1; } } @end </code></pre> <p>and test class:</p> <pre><code>#import "CodeCoverageTests.h" #import "SomeClass.h" @implementation CodeCoverageTests - (void)testExample { SomeClass *obj = [[SomeClass alloc] init]; [obj performWork:YES withValue:3]; STAssertEquals(obj.someValue, 3, @"Value was not 3"); } @end </code></pre> <p>Ideally, I'd like to be notified in some way that when the tests execute, the <code>else</code> clause in the <code>performWork</code> method is never fired. </p> <p>I thus have the following questions:</p> <ol> <li>Is the root problem that there's no support for what I'm trying to do with the new compiler? </li> <li>Is the only solution the one described by <a href="https://stackoverflow.com/a/7941974/800788">user chown</a> in response to the question I linked above? </li> <li>Will I be able to use CoverStory (or something similar) if I follow the solution from 2) ?</li> </ol> <hr> <p><strong>Update:</strong> After some struggle, I was finally able to find the location of the "SomeClass.gcno" and "SomeClass.gcda" files (thanks @bjhomer - see <a href="https://stackoverflow.com/a/4282467/800788">this link</a>), and they depicted beautifully that the <code>if</code> part of the conditional statement in <code>performWork</code> was covered (and the <code>else</code> was not). To make sure, I modified the test as follows:</p> <pre><code>- (void)testExample { SomeClass *obj = [[SomeClass alloc] init]; [obj performWork:NO withValue:3]; STAssertEquals(obj.someValue, 2, @"Value was not 2"); } </code></pre> <p>After re-building and re-execution of the unit test, I reloaded the .gcno and .gcda files. CoverStory showed that the coverage changed to the <code>else</code> part of the <code>performWork</code> method. There was one small caveat however: </p> <ol> <li>I needed to modify the build settings of the <code>&lt;TargetName&gt;</code> (not the <code>&lt;TargetNameTest&gt;</code> as shown <a href="http://www.infinite-loop.dk/blog/2011/12/code-coverage-with-xcode-4-2/" rel="nofollow noreferrer">here</a>) in order for the "SomeClass.gcno" and "SomeClass.gcda" files to be created in <code>...&lt;TargetName&gt;.build/Objects-normal/i386/</code> directory. </li> </ol> <p>Thanks again for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload