So make it clear what you need to check in your function.
My guess is the desire to test both of them. But since the problem you are mentioning, it seems to me impossible to check if your getUserEnterpriseCalendar function really works on the simulator, because it will not return anything anywhere (except that you create a script on your build server to allow the simulator to subscribe or add your calendar on it)
However, I can suggest that you make fun of the getUserEnterpriseCalendar function and make the assumption in your unit test that getUserEnterpriseCalendar will return the correct value in any environment. You may need to execute the function of the calculated value and pass the MeetingFetcher 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 this can help even just give you some ideas.
tpeodndyy
source share