How to display Xcode code coverage when it's not displaying?
Asked Answered
C

9

36

I have been trying to get the code coverage for my project using Xcode 9. All test cases run successfully but did not generate the code coverage report under the Code coverage tab.

I tried the following things:

  1. Enable the Gather code coverage in the scheme.

  2. Enable Code Coverage Support for my target.

  3. Enable the Showcase bundle option.

    Is there an extra setting require to check the code coverage report ? or should I miss something? Thanks in advance.

Corrinacorrine answered 7/11, 2017 at 11:41 Comment(4)
Did you try to run it on an actual device? This might be a bug.Calla
no i am running on simulator. let me try on device.Corrinacorrine
Try to follow steps provided under Apple's documentation.Unitive
Still got issues, try this.Unitive
U
51

Issue Resolve in Version 9.3, to get the code coverage Target -> Test -> Options -> CodeCoverage See image:

image


Unmeant answered 31/5, 2018 at 11:33 Comment(1)
Anyone know how to set this "Gather coverage for some targets" from command line? I just want output for the main app and not all the frameworks and extensions.Wendalyn
V
29

If you want to see the code coverage in the right side of the editor, make sure you have Show Code Coverage selected in the Editor drop down menu.

Show Code Coverage

Vena answered 11/9, 2018 at 18:54 Comment(1)
In my case were two issues, the explained here and Test -> Options -> CoverageRosenblatt
A
14

I'm pretty sure they just moved the code coverage to a new location. I'm seeing it now as part of the report navigator (see screenshot below).

To get there, first turn on code coverage support (edit scheme -> test -> options -> check code coverage box) then look on the left hand side of xcode at the navigator. At the top you will see a bunch of icons. Click on the last one on the right (it looks like a message bubble).

Within that tab, you will see all the tests you ran. Within each test is a "coverage" item. Click on one of those to get the coverage report for that specific test.

xcode window

Andriette answered 7/8, 2018 at 18:52 Comment(0)
H
12

There was known bug on Apple side addressed missed code coverage for UI tests targets (https://openradar.appspot.com/24006783).

Xcode Version 9.3 beta (9Q98q) seems resolves issue as long as Debug executable not enabled in Test schema.

In Xcode build scheme editor Test -> Info tab -> Debugger make sure that checkbox Debug executable is unchecked.

Homing answered 27/1, 2018 at 15:18 Comment(0)
A
9

I didn't find Options in Target -> Test. No Options in Target -> Test

I found the Code Coverage setting moved to the Test plan configurations.
Select the Autocreated test plan in the Test navigator and choose Edit Test Plan -> find Code coverage in Configurations. Then you should save it as a new Test plan.

Code coverage in the Test plan

Alternant answered 18/4, 2023 at 16:29 Comment(0)
Q
1

If you like me and don't see the Option tab (or any tab) on Target -> Test in your schema, it means you need to add test schema to your app or you select wrong Target.

First select Manage Schemes... and see do you have yourTargetTest and if it is checked or not.

Manage Schemes...

Second, add (small + button) and select your test target.

enter image description here

By the way, if you don't have Test Bundle, please add it to your boundles list first.

enter image description here Now you will see your test bundle and can select and edit it. And you will see the Options tab, and Code Coverage as mentioned in accepted answer.

Quench answered 11/5, 2020 at 16:32 Comment(0)
D
0

The old bug when you have had to deselect Debugger 'Debug executable' in the Info tab of Edit Scheme (for Test Debug) - seems to be solved, but there is a new one on ARM M1, so if there is no test coverage showing - try building for "My Mac (Rosetta)" or if if fails due to use of platform-specific frameworks like UIKit in my case for "My Mac (Mac Catalyst, Rosetta).

It will be slower, but it should work.

Delectable answered 27/10, 2021 at 13:12 Comment(0)
A
0

If you're working on a framework, you'll need to enable code coverage in two places.

First, you'll need to create a standalone scheme for testing the framework. To enable code coverage for this scheme, go to your project's scheme and select "Edit Scheme." Then, select "Test" from the left-hand menu and check the box next to "Gather coverage data."

Second, you'll need to enable code coverage for the Clang compiler. To do this, go to your project settings and select the target for your framework. Then, go to "Build Settings" and select "Apple Clang - Code Generation." Since tests are only run in DEBUG mode, make sure to select "YES" for the "Enable Code Coverage Support" option under DEBUG.

Code Coverage

Andrade answered 2/3, 2023 at 21:19 Comment(0)
S
0

Found the enable code coverage option under test plan -> configuration -> code coverage was set to off -> enable code coverage

Stereography answered 18/7, 2024 at 12:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.