Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode and Code Coverage

My application was initially not written for the Mac platform, so it has it's own unit-test system which can be triggered by a command-line. Is it possible to make use of the code coverage support in Xcode by just executing it?

I tried to make it run as a UnitTest which triggers the 'main(...)' function of my application manually (see code block), but since this process is started by the application 'xctest' a lot of things are missing like resources from my application bundle, etc (incorrect or wrong paths, ...).

- (void)testExample {
  int main(int argc, char* argv[]);
  main(...);
}

Is there any way just to tell Xcode that my application should be started so it can output the code coverage that can be reviewed inside Xcode?

like image 320
HelloWorld Avatar asked Aug 01 '16 18:08

HelloWorld


People also ask

How do I test coverage in Xcode?

To view the coverage reports: Select the Report Navigator in the navigator pane on the left (⌘8) Select the latest Test run in the navigator pane. Select the Coverage tab in the editor.

What is code coverage in IOS?

Code coverage is a feature in Xcode 7 that enables you to visualize and measure how much of your code is being exercised by tests.

How do I check code coverage?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.


1 Answers

I didn't use XCode coverage tools but I used gcov before. Anyway in this article there is information how to create llvm coverage report. So you can use your unit-test system with llvm's coverage flags and then create .profdata report with llvm-profdata tool.

As I understand Xcode's code coverage tool also creating .profdata report and uses it. I have no straightforward solution but you may find something with this information. If you find a way to make Xcode uses your .profdata it's done :)

like image 142
halit Avatar answered Sep 28 '22 08:09

halit