1

I'm trying to understand if there is something within XCTest framework that prevents my test class from seeing convenience initializer defined in a class for the module I'm testing? I'm using @testable import to override and subclass non-open classes.

The tests were running correctly before. Is this some XCode 11.4 bug?

I have multiple versions of this error, every time it is the convenience initializer, even if it is declared public.

Error Missing argument for parameter 'repository' in call

//Inside FrameworkModule

public class RealObject {

    init(repository: SomeRepository) {
       //designated initializer
    }


    convenience override init() {
    // Use default repository
    }
}

//Inside Test class:
@testable import FrameworkModule

class MockObject: RealObject {
    //Inherits initializers from RealObject

}

class TestHelper: NSObject {   
var mockObject: MockObject!

}
    override init() {
       mockObject = MockObject() //Error Missing argument for parameter 'repository' in call
    }
}
Alex Stone
  • 46,408
  • 55
  • 231
  • 407

1 Answers1

0

I'm struggling with the same problem, and found out that this is due to a change mentioned in Xcode 11.4's release notes.

Convenience initializer inheritance for subclasses defined outside the module that defines the base class now comes with additional restrictions. When these subclasses have a base class with non-public designated initializers, they no longer automatically inherit convenience initializers from their superclasses. To restore this automatic inheritance behavior, the base class must ensure that all of its designated initializers are public or open. (51249311)

I believe if you make all of your designated initializers public, you should be able to see it from your unit test class.

Community
  • 1
  • 1
jeffctown
  • 176
  • 1
  • 1
  • 8