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 here. I'm able to modify the Build Settings for the test target correctly, and link the "libprofile_rt.dylib" file fine.
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 here. In addition, I've installed CoverStory.
The author in the first link mentions "Just run your unit tests and view the code coverage data as usual"; however, I cannot find .../Objects-normal/i386
.
Just to get things working, 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 test 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'd like to be notified in some way that when the tests execute, the else
clause in the performWork
method is never fired.
I thus have the following questions:
- Is the root problem that there's no support for what I'm trying to do with the new compiler?
- Is the only solution the one described by user chown in response to the question I linked above?
- Will I be able to 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 "SomeClass.gcno" and "SomeClass.gcda" files (thanks @bjhomer - see this link), and they depicted beautifully that the if
part of the conditional statement in performWork
was covered (and the 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-building and re-execution of the unit test, I reloaded the .gcno and .gcda files. CoverStory showed that the coverage changed to the else
part of the performWork
method. There was one small caveat however:
- I needed to modify the build settings of the
<TargetName>
(not the<TargetNameTest>
as shown here) in order for the "SomeClass.gcno" and "SomeClass.gcda" files to be created in...<TargetName>.build/Objects-normal/i386/
directory.
Thanks again for your help!