Segmentation Error 11 when code coverage is enabled in Swift

While I run unit tests with XCTest in Swift, they work fine when code coverage is disabled. However, as soon as I try to enable code coverage, I have a failed build / test with 4 classes, resulting in the following error message: Command failed due to signal: Segmentation error: 11 .

+4
source share
3 answers

Here's what worked for me (since all other suggestions didn't work in my case). I was getting a segmentation error 11 in a specific Swift class when trying to run unit tests with code inclusion enabled. It turns out that we had a ternary expression on a class property like this:

let cellBorder : CGFloat = MyHelperClass.isIPad() ? 10.0 : 6.0

To do this, lazy var fixed the problem:

lazy var cellBorder : CGFloat = MyHelperClass.isIPad() ? 10.0 : 6.0

To be clear, the code compiled and worked perfectly until we tried to enable code coverage . I also found this Open Radar and this post of the guy who outlined the solution. This seems to be Apple's mistake.

+3
source

Without code, build settings, etc. It's hard to say for sure, but you need to verify that you use the import flag @testablein your unit test classes.

, MyApp unit test, @testable import MyApp.

, , , . Apple:

| Apple Developer

+2

Source: https://habr.com/ru/post/1623096/


All Articles