I am creating an iPhone 5.0 project in Xcode 4.2 and would like to find code coverage when doing unit tests. I am completely new to the Xcode environment and I have completed the following steps here . I can correctly change the build settings for the target and link the file "libprofile_rt.dylib".
At this point, when I run the tests (using Command-U), the code compilation and tests pass. I do not encounter the problem described here. In addition, I installed CoverStory .
The author in the first link refers to "Just run your unit tests and view the code coverage data as usual" ; however, I cannot find .../Objects-normal/i386 .
Just for everything to work, I created a new project with the following class:
#import "SomeClass.h" @implementation SomeClass @synthesize someValue; -(void)performWork:(BOOL)now withValue:(int)value { if (now) { someValue = value; } else { someValue = value - 1; } } @end
and testing class:
#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
Ideally, I would like to somehow inform you that when executing tests, the else clause in the performWork method never starts.
I have the following questions:
- Is the root problem a lack of support for what I'm trying to do with the new compiler?
- The only solution described by user chown in response to the question I linked above?
- Can I use CoverStory (or something similar) if I follow the solution from 2)?
Update: After some struggle, I was finally able to find the location of the files "SomeClass.gcno" and "SomeClass.gcda" (thanks @bjhomer - see this link ), and they beautifully depicted that the if part of the conditional statement in performWork was covered (and else was not). To make sure, I modified the test as follows:
- (void)testExample { SomeClass *obj = [[SomeClass alloc] init]; [obj performWork:NO withValue:3]; STAssertEquals(obj.someValue, 2, @"Value was not 2"); }
After re-creating and re-running the unit test, I reloaded the .gcno and .gcda files. CoverStory showed that coverage has changed to the else part of the performWork method. However, there was one slight caveat:
- I needed to change the settings of the
<TargetName> assembly (and not <TargetNameTest> , as shown here ) so that "SomeClass.gcno" and "SomeClass.gcda" should be created in the directory ...<TargetName>.build/Objects-normal/i386/ .
Thanks again for your help!