Skip to content

Instantly share code, notes, and snippets.

@4np
Created August 1, 2024 16:15
Show Gist options
  • Save 4np/fa4eba3412d160f39be8352f5c80b557 to your computer and use it in GitHub Desktop.
Save 4np/fa4eba3412d160f39be8352f5c80b557 to your computer and use it in GitHub Desktop.
Run tests using a particular locale and / or language (useful for SPM projects)
import XCTest
class SomeTests: XCTestCase {
override class func setUp() {
super.setUp()
UserDefaults.standard.set("en_US", forKey: "AppleLocale")
UserDefaults.standard.set(["en_US"], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
}
override class func tearDown() {
super.tearDown()
UserDefaults.standard.removeObject(forKey: "AppleLocale")
UserDefaults.standard.removeObject(forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment