CodeCoverage (for UI tests) shown only for code from Application bundle, but missed for code from shared Framework.

Originator:volodymyr.gorlov
Number:rdar://24006783 Date Originated:24-Dec-2015
Status:Open (DUPLICATE OF 23913271) Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:100%
 
Summary:
iOS application [Xcode target UITestingDemo] (see https://github.com/vgorloff/Radar24006783) contains UI Tests [UITestingDemoUITests] and Logic Tests [UITestingDemoTests]. iOS application also uses Shared Framework [UITestingDemoKit] with reusable code.

After running UI Tests and Logic Tests within target, the CodeCoverage report contain the following statistics:

- Code usage from Application Bundle (produced by UI Tests)
- Code usage from Shared Framework (produced by Logic Tests)

But the CodeCoverage report does not contains the following statistics:

- Code usage from Shared Framework (produced by UI Tests)

Steps to Reproduce:
Open attached project in Xcode. Select iPhone 6s as destination. Select shared build schema "UITestingDemo" and run tests (press cmd+U).

Expected Results:
CodeCoverage report should show statistics about MyView class usage.

Actual Results:
CodeCoverage report show that MyView class usage is zero (0) which is not truth because this class and it's methods used during UI Tests.

Version:
Xcode 7.2 (7C68), iOS 9.2 Simulator (13C75)

Notes:
One more issue:
Disabling Logic Tests [Xcode target UITestingDemoTests] from build schema cause cause CodeCoverage report show zero statistics for all classes (zero code usage).

Configuration:
MacBook Pro (Retina, 15-inch, Late 2013)
Mac OS X El Capitan 10.11.2 (15C50)

Comments

Xcode Version 9.3 beta (9Q98q)

Xcode Version 9.3 beta (9Q98q) seems resolves issue as long as Debug executable not enables:

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

Example project: https://github.com/vgorloff/Radar24006783

By volodymyr.gorlov at Jan. 27, 2018, 3:05 p.m. (reply...)

Any update on this issue?

Hi, Even I want the embedded framework to show the code coverage. Is there a way? Any updates on this issue?

Found workaround.

As long as project meet following criteria the workaround will work:

  1. UI elements from your shared framework (if any) not used directly in storyboards or xib files. For example: "Custom Class" in interface builder configured to "Inherit Module From Target".

Workaround:

  1. Duplicate "Application" target. For example existing "Helo.app" target duplicated to "Helo-UITests.app" target.
  2. Make sure that new target does not link to your shared frameworks anymore.
  3. Include all source files to be compiled in new target (i.e. "Helo-UITests.app")
  4. Create folder name "Workaround" somewhere inside your project. For example: Tests/UITests/Workaround
  5. Create files "Workaround.h" and "Workaround.c" inside "Workaround" directory. See example contents here: https://github.com/vgorloff/Radar24006783
  6. Create file "module.modulemap" inside "Workaround" directory. See example contents here: https://github.com/vgorloff/Radar24006783
  7. Set build property "Import Paths" for new target (i.e. "Helo-UITests.app") to point to the "Workaround" directory.

As result:

  1. Your source code and UI files remains the same.
  2. The project now has fake Application target (i.e. "Helo-UITests.app") for UI Testing purpose only.
  3. Imports of Shared frameworks replaced with fake Swift modules, so that there is no Compile errors.

See full example here: https://github.com/vgorloff/Radar24006783

By volodymyr.gorlov at July 30, 2017, 7:34 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!