How to test a function/computed property that needs device specific information?
So let clarify what you actually have to test in your function.
MeetingsFetcher().getUserEnterpriseCalendar()
calendar.title.firstMatch(from: Regex.organizerNameFromEKCalendar)
My assumption is your want to test both of them. But as the issue you mention I think it's impossible to actually test if your getUserEnterpriseCalendar
function is actually work correctly on simulator because it won't return anything anywhere (except you create the script on your build server to let simulator subscribe or add your calendar on it)
However I can suggest you to mock getUserEnterpriseCalendar
function and make an assumption in your unit test that getUserEnterpriseCalendar
will return correct value in any environment. You may need to chnage your computed property to function and pass MeetingFetcher as parameter for this.
// function modification
static func name(from meetingFetcher: MeetingFetcher) -> String {
if let savedName = defaults.string(forKey: "name") {
return savedName
}
// calendar is a specific EKCalendar members of my company will have.
guard let calendar = meetingFetcher.getUserEnterpriseCalendar().first,
let parsedName = calendar.title.firstMatch(from: Regex.organizerNameFromEKCalendar) else {
return nil
}
defaults.set(parsedName, forKey: "name")
return parsedName
}
// In testing code.
func testOrganizationCalendar() {
class MockedMeetingFetcher: MeetingFetcher {
override func getUserEnterpriseCalendars() -> [EKCalendar] {
let calendar1 = EKCalendar()
calendar1.title = "ExpectedToMatchRegexTitle"
return [calendar1]
}
}
XCTestAssertEqual(YourClass.name(from: MockedMeetingFetcher()), "Hure!!!")
}
I hope it may help even just give you some ideas.
Couldn’t communicate with a helper application on 10.10
This issue is very likely due to sandboxing as @ingrid already pointed out. But if you want to distribute our app(s) via the Mac App Store you can not just switch sandboxing off (which isn't recommended anyway). Instead enable the 'Outgoing Connections' capability.
- Click on your project file
- Choose the App's build target
- On the 'Capabilities' tab extend 'App Sandbox'
- Enabled the 'Outgoing Connections (Client)' checkbox
How to test a function/computed property that needs device specific information?
So let clarify what you actually have to test in your function.
MeetingsFetcher().getUserEnterpriseCalendar()
calendar.title.firstMatch(from: Regex.organizerNameFromEKCalendar)
My assumption is your want to test both of them. But as the issue you mention I think it's impossible to actually test if your getUserEnterpriseCalendar
function is actually work correctly on simulator because it won't return anything anywhere (except you create the script on your build server to let simulator subscribe or add your calendar on it)
However I can suggest you to mock getUserEnterpriseCalendar
function and make an assumption in your unit test that getUserEnterpriseCalendar
will return correct value in any environment. You may need to chnage your computed property to function and pass MeetingFetcher as parameter for this.
// function modification
static func name(from meetingFetcher: MeetingFetcher) -> String {
if let savedName = defaults.string(forKey: "name") {
return savedName
}
// calendar is a specific EKCalendar members of my company will have.
guard let calendar = meetingFetcher.getUserEnterpriseCalendar().first,
let parsedName = calendar.title.firstMatch(from: Regex.organizerNameFromEKCalendar) else {
return nil
}
defaults.set(parsedName, forKey: "name")
return parsedName
}
// In testing code.
func testOrganizationCalendar() {
class MockedMeetingFetcher: MeetingFetcher {
override func getUserEnterpriseCalendars() -> [EKCalendar] {
let calendar1 = EKCalendar()
calendar1.title = "ExpectedToMatchRegexTitle"
return [calendar1]
}
}
XCTestAssertEqual(YourClass.name(from: MockedMeetingFetcher()), "Hure!!!")
}
I hope it may help even just give you some ideas.
Related Topics
How to Change/Modify The Displayed Title of an Nspopupbutton
Swift Spritekit Get Visible Frame Size
Adding Data to a Specific UId in Firebase
Firebase Authentication: Linking Multiple Accounts in Swift
Open Attachment from Mail Using iOS 8 App [Swift]
How to Get and Save The Mixed of Multiple Audios in to Single Audio in Swift
Cocos2D Fcm Push Notification Not Working
Expose an Interface of a Class Loaded from a Framework at Runtime
Difference Between Orientation and Rotation in Scnnode
Read UId from Nfc Mifare Tag iOS 13
Getting an Ip Address and Port Number from a Sockaddr_In Struct in Swift
How to Drag a Working Slider Using Swiftui
Validatemenuitem or Menuwillopen Not Called for Nsmenu
Swift 4 Base64 String to Data Not Working Due to String Containing "Incomplete" Emoji
Multi-Users Chat Room Data Structure in Firebase Database
Unexpectedly Found Nil While Unwrapping an Optional Value with Avaudioplayer