Allocating Ekeventstore Throws Warnings

How to test a function/computed property that needs device specific information?

So let clarify what you actually have to test in your function.

  1. MeetingsFetcher().getUserEnterpriseCalendar()

  2. 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

Sample Image

How to test a function/computed property that needs device specific information?

So let clarify what you actually have to test in your function.

  1. MeetingsFetcher().getUserEnterpriseCalendar()

  2. 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



Leave a reply



Submit