Hi everyone!
I'm developing an app using TDD-practices and one of my classes are dependent on callbacks from the CoreBluetooth-framework. I've isolated everything in a way that makes my class unaware of that it is using a concrete CBCentralManager, but just an object conforming to a certain protocol. In production I have an extension on the contrete CBCentralManager to make it conform to that protocol.
However - In my test suite, I need to call some of the delegate methods of the CBCentralManager and provide objects for the callback methods. In this case a CBPeripheral. So I thought i could just instantiate, or possibly, subclass CBPeripheral, and use an instance of that and provide as argument for the callback methods.
let a = CBPeripheral() // 'init()' is unavailable
class MockCBPeripheral: CBPeripheral {}
let b = MockCBPeripheral() //' MockCBPeripheral' cannot be constructed because it has no accessible initializers
class MockCBPeripheral2: CBPeripheral {
override init() {
// Cannot override 'init' which has been marked unavailable
}
}
Is there any other approach I can take to mock these classes?
Thanks in advance.
/ Albin