I have a class with few public and private members like below :
public class ReviewManager {
public static let shared = ReviewManager()
private static let startDateKey = "StartDate"
private static let popupLastSeenKey = "LastSeen"
private static let lastVersionPromptedForReview = "lastVersionPromptedForReview"
private(set) var startDate: Date {
get {
Date()
}
set { }
}
private(set) var lastPopupDate: Date? {
get {
}
set {
}
}
private(set) var lastVersionPromptedForReview: String {
get {
}
set {
}
}
private(set) var appCurrentVersion: String {
get {
// Get the current bundle version for the app
guard let currentVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
else {
logError("Expected to find a bundle version in the info dictionary")
return ""
}
return currentVersion
}
set { }
}
private func requestReview() {
SKStoreReviewController.requestReview()
lastPopupDate = Date()
lastVersionPromptedForReview = appCurrentVersion
}
public func requestReviewIfPossible() {
let today = Date()
if lastPopupDate == nil {
if allowedToPresentToday() && allowedToPresentForThisVersion() {
requestReview()
}
} else {
if let lastPopupDate = lastPopupDate {
if allowedToPresentToday() && allowedToPresentForThisVersion() {
requestReview()
}
}
}
}
private func allowedToPresentToday() -> Bool {
let calendar = Calendar(identifier: .gregorian)
let today = Date()
let components = calendar.dateComponents([.weekday], from: today!)
return components.weekday == 5 || components.weekday == 6
}
private func allowedToPresentForThisVersion() -> Bool {
let allowedToShowForThisVersion = (appCurrentVersion != lastVersionPromptedForReview) ? true : false
return allowedToShowForThisVersion
}
}
Now I want to write Unit tests for all the private functions in this class. I can access private properties in this class by making access modifier as
private(set)
But private functions can not be accessed outside the class.
Is there any way to unit test private functions in Swift ?