Code Coverage Result Is Not Accurate to Real Coverage in Xcode 7

Xcode 9 code coverage on unit tests showing wrong %

I believe you'll find the answer here Code coverage result is not accurate to real coverage in Xcode 7

Briefly it says to use

@testable import <yourapp>

In each test file and don't add your app .swift files to the test targets.

Works for me.

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

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

image


Why Xcode 7 shows around 12% code coverage when there are no unit tests at all?

As of Xcode 8, running the tests actually instantiates the app. That means that all the initialization code is executed. This will show as covered code in the test coverage report.

What is the meaning of rectangle areas with stripes, while having test coverage enabled in Xcode?

The striped rectangles indicate partial code coverage. Somebody just asked this question elsewhere and in looking at some test cases, I realized that if you hover your mouse over a line with the stripes, you get something like this:

Partial code coverage

As you'll notice, part of the line is green and part of it is red. The green part is for the condition which comes under code coverage since that part was executed. The red part is for the error message which was not executed since the test passed. Hope that makes sense?

Code coverage in Xcode without tests (for manual run)

The solution was suggested by someone here: https://github.com/SlatherOrg/slather/issues/209

You could try having a XCUITest that sleeps forever, then manually use the app, and see if on termination the coverage files are generated.

I simply tried the solution and it worked perfectly for me:

class FooTests: XCTestCase {

override func setUp() {
super.setUp()
let app = XCUIApplication()
app.launch()
}

func testBalances() {
sleep(30)
XCTAssert(true)
}
}

After the test succeeded on XCTAssert(true), I could see the code coverage for the manual use cases. You can play around with the sleep(30) to match your requirement.



Related Topics



Leave a reply



Submit