Reputation: 369
While I am running unit tests with XCTest in Swift, they run fine when code coverage is turned off. However once I try to enable code coverage, I have a failed build/test with 4 classes giving the following error message: Command failed due to signal: Segmentation fault: 11.
Upvotes: 4
Views: 1618
Reputation: 1
In my case, i was building through the cli running the xcodebuild command with Release configuration and no provitionings configured, when i switched to Debug config build and tests worked just fine
Upvotes: 0
Reputation: 811
See this bug report on similar issue. https://bugs.swift.org/plugins/servlet/mobile#issue/SR-1825
I got the same error when implementing a protocol which required an optional variable that I implemented as a lazy var.
Upvotes: 0
Reputation: 5066
Here is what worked for me (as all the other suggestions did not work in my case). I was getting a segmentation fault 11 on a particular Swift class when trying to run unit tests with code coverage turned ON. It turns out that we had a ternary expression on a class's property like so:
let cellBorder : CGFloat = MyHelperClass.isIPad() ? 10.0 : 6.0
Making it a lazy var fixed the problem:
lazy var cellBorder : CGFloat = MyHelperClass.isIPad() ? 10.0 : 6.0
To be clear, the code compiled and worked fine until we tried turning on code coverage. I also found this Open Radar and this guy's post that outlined the solution. Appears to be an Apple bug.
Upvotes: 3
Reputation: 1129
Without code, build settings, etc. it's hard to say for sure but one thing you should check is to make sure that you are using a @testable
import flag in your unit test classes.
For instance with a project named MyApp
at the top of your unit test class you would include with the following import @testable import MyApp
.
You also want to check to ensure that you've followed the process for enabling coverage all the way through. That information is documented on Apple's developer portal:
Code Coverage | Apple Developer
Upvotes: 2