How can I enable code coverage in Xcode 14.3? (It appears different from other versions)
Asked Answered
N

5

20

Normally I would follow these steps. Basically I woult tap on my scheme, then edit, then Test, then I'd have a nice neat enable code coverage box I can tick. However, with 14.3, I don't see the info | options etc tabs, instead I see this view. And enable code coverage isn't there. Usually, it would be between Build configuration and Debugger.

14.3

enter image description here

Old view: enter image description here

I don't see show code coverage here either:

enter image description here

Nominee answered 7/5, 2023 at 5:31 Comment(1)
I created my own custom scheme. When I switched to the default scheme, code coverage was available.Nominee
A
29

Enabling Code Coverage has moved to Test Plan configuration which is designed to manage your tests and was introduced in Xcode 11 at WWDC 2019.

Do the following steps to enable it:

  1. Press Command + Option + u to bring the Edit Scheme window

enter image description here

  1. Hover over the Autocreated test plan to show the disclosure button and click it.

enter image description here

  1. Go to the Configuration tab :

    enter image description here

  2. Find Code Coverage and enable it :

enter image description here

Aureus answered 26/7, 2023 at 23:36 Comment(2)
This occurred again for me, and this answer was the only one to fix it.Nominee
@igor-muzyka did you save it? Command SEppes
L
6

You can enable it on the test plans configuration. Go to the Test navigator. Click on the "Test Plan" dropdown and then select "Edit test plan"

enter image description here

You will be able to update the shared configs of your test plans, including conde coverage enabling: enter image description here

Latonia answered 7/5, 2023 at 7:40 Comment(1)
This was on by default for me but doesn't provide any test coverageWampum
S
5

Once you successfully turn on code coverage (as described by the answers above), do the following:

  1. Run your tests.
  2. Right-click on a test.
  3. Choose "Jump to Report

enter image description here

  1. Select Test Example Test (your app name)

enter image description here

  1. From the drop down, choose "Coverage"

enter image description here

  1. View the report.

-

Stove answered 29/12, 2023 at 8:0 Comment(0)
D
1

Once you turn on the code coverage, check that your file .xctestplan has been created and added to your project. Then on the last tab of left panel of Xcode, the 'Show the report navigator', once your test has been launched you should have a 'coverage' line that will give you access of all your coverage xcode-screenshot-code-coverage

Danseur answered 16/8, 2023 at 9:42 Comment(1)
This is answer for my case, any others was not helpful. I migrated my project from native Xcode configurations to the Tuist and it broke test coverage calculation.Autograft
G
1

Edit your schema -> Test Plan as suggested by @Mehdi Ijadnazar more above and then:

  1. Enable Code Coverage enter image description here

  2. Make sure that .xctestplan has been created. enter image description here

  3. Verify the file is in your project. enter image description here

  4. Run tests enter image description here

Goethite answered 30/8, 2023 at 5:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.