How to make a unit test in a swift package with different current locales?

I have a swift package with a function that formats a HKQuantity using the current locale. I want to write a unit test with all locales the package is localized for. I do not want to insert a separate locale parameter, I want to test the function with the current locale as I use the function only with the current locale.

Can I set the current locale for this use case in the code somehow?

Example:

do {
    let quantity = HKQuantity(unit: unit, doubleValue: 0.955)
    let result = quantity.formattedAsOxygenSaturation(precision: .better)
    let expectedResult = "95.5 %"
    XCTAssertEqual(result, expectedResult)
}

Thanks!

Answered by jlilest in 773371022

I would look to see if the formatted function has a version that includes the locale as a parameter and add tests for whatever locales you need to test.

Accepted Answer

I would look to see if the formatted function has a version that includes the locale as a parameter and add tests for whatever locales you need to test.

How to make a unit test in a swift package with different current locales?
 
 
Q