XCode 11.4 code coverage is broken

Since I upgraded to XCode 11.4, found that the code coverage is completely broken.

Here are the screenshots before and after upgrade, code coverage, from Cubertura report:

Before

coverage line-rate="0.8183180370855966" branch-rate="1.0000000000000000" lines-covered="4369" lines-valid="5339"

After

coverage line-rate="0.9479166666666666" branch-rate="1.0000000000000000" lines-covered="273" lines-valid="288"

Looking into the xcode coverage, here are my findings:

* file coverage is either 100% covered or 0%. Only 2 files have something between.

* all the covered code contains only variable declarations and even not all of the variables within a class are marked covered.


Any ideas on what happened?

Replies

Yes seems broken as of Xcode 11.4 .


I did a small experiment where I put a breakpoint in one func while running tests just to be 100% it is executed during that test and it ended up showing 0 coverage for that func but the other func in the same file has coverage.

Hey! Is there any fix for this?
I've been diving in into this case in our repository and I see the following:


- The projects within the workspace that generate a framework that is then linked into the app, generate the coverage as expected.
- The app target which doesn't generate a .framework output only generates coverage report for some variables (no body at all). The variables included are the ones that have some kind of value assigned/computed when creating them.
Here is a screenshots that shows this:


https://imgur.com/1VZqFp2


This ViewController has the following implementation:


final class AddCardCountriesViewController: UIViewController, HeaderWithShadowProtocol {
  
  private let viewModel: AddCardViewModel
  
  let keyboardAwareDecorator: KeyboardAwareDecorator
  
  let contentView: UIView
  
  let textFieldView = TextFieldWithIconView(icon: UIImage.searchBarIcon?.mirroredIfNeeded())
  
  let tableView = UITableView(frame: .zero, style: .grouped)
  
  init(viewModel: AddCardViewModel) {
    self.viewModel = viewModel
    
    let contentView = UIView()
    self.contentView = contentView
    
    self.keyboardAwareDecorator = KeyboardAwareDecorator(
      decoratedView: contentView,
      dismissKeyboardWhenDecoratedViewIsTapped: false)
    
    super.init(nibName: nil, bundle: nil)
  }
}


Also, in the coverage column in xcode we only see the 0 hits on the properties that have some value computed by default (textFieldView and tableView)


Please let me know if I should provide more context around this issue and if there's a fix apart from downgrading to Xcode 11.3.


Best,


Mauro

Still not fixed in Xcode 11.5. Is there any workaround?
Please file a report on Feedback Assistant describing your problem and if possible add the test result bundle to it.

looks like only swift is not woking and objc is working fine...
Still a issue in xCode 12.0.1, has anyone found a workaround ?
I was experiencing this issue, and I found that switching the Swift compilation mode build setting to "incremental" (instead of "whole module") for the build configuration being used for the tests fixed it, and the coverage counts now look accurate, instead of acting like 90% of the Swift code isn't even code.

(This limitation doesn't seem to be documented anywhere, unfortunately.)
I'm experiencing the same issue in Xcode 12.1