How about opening up your private properties and methods in an extension and only use that for testing. Remove the extension (comment it out) when not testing.
Here I put a 'T' in front of the private method or property name in the extension.
For example:
class MyClass {
private var privateString: String?
private func privateSetName(name: String) {
privateString = name
}
extension MyClass { // for testing only
var TprivateString: String? {
get {
return self.privateString
}
}
func TprivateSetName(name: String) {
privateSetName(name)
}
}
then in your XCTest you can do:
func testThatNameIsSet() {
let myClass = MyClass()
myClass.TprivateSetName("myName")
XCTAsserNotNil(myClass.TprivateString, "Name should be set.")
}