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:
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:
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
Xcode 8 Memory Graph Says "No Selection" and Not Working
Using Haneke to Cache Then Play Mp4 Files with Avplayer
My Uiviews Muck-Up When I Combine Uipangesturerecognizer and Autolayout
Setting Uiimageview Image Affects Layout Constraints
Shift Avplayer Captions When Subview Overlaps Them
Simplest Way to Implement a "Read More" Button to Expand a Uitextview in iOS Swift 2
My App Is Rejected with Exception Exc_Breakpoint (Sigtrap)
Swift - Using Cgcontext to Draw with Finger
Adding Custom Game Logic to Scene Kit (Swift)
Swift Tableview Cell Radio Button Implementation
Why am I Getting Com.Facebook.Sdk.Login Error 308
Show Bounding Box While Detecting Object Using Arkit 2
How to Programmatically Check and Open an Existing App in iOS 8
Automatically Change Cell Height Based on Content - Swift
Output Video Size Huge Using Hevc Encoder on iOS
Cannot Set Color of Button's Label Inside Menu in Swiftui