Unable to see code coverage in Xcode 4.2

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!

+4
source share
1 answer

It seems your main problem is that you cannot find the Build/Intermediates/<SchemeName>.build/<ConfigurationName>-<PlatformName>/<TargetName>.build/Objects-normal/<ArchitectureName> . This directory is always used when creating, regardless of whether you are performing code coverage. That all intermediate files generated by the compiler are saved, as well as where the final .gcno and .gcda must exist if you are performing code coverage. If you cannot find this directory, the problem is not coverage, the problem is that you need to find this directory.

To answer your questions.

  • Code coverage is supported by the LLVM compiler, starting with Xcode 4.2. It will not work with LLVM-GCC, so make sure you are not using this.
  • No, there is no need to hack support for GCC 4.2 in Xcode 4.2. I am starting code coverage with Xcode 4.2 right now without doing any of this.
  • You should be able to use CoverStory anyway; Hacking in support of GCC 4.2 will not change where the embedded products go.
+1
source

Source: https://habr.com/ru/post/1390329/


All Articles