Different approach without calling methods on your String
Prerequisites
You are using NSLocalizedString
.
Step 1
Make sure you add the translations to your test targets (Go to your
Localizable
file and on the right side you can tap your UI test
targets).
Step 2
Add this somewhere in your main target
#if DEBUG
// Can be changed by UI tests to get access to localized content
var bundleForLocalizedTexts = Bundle.main
#else
let bundleForLocalizedTexts = Bundle.main
#endif
Step 3
Add this value to the parameter bundle
in all your
NSLocalizedString
s, like this:
NSLocalizedString(
"localized",
bundle: bundleForLocalizedTexts,
comment: ""
)
Step 4
Override the method setUp in your XCTestCase
subclass and add this
line:
bundleForLocalizedTexts = Bundle(for: MySubclass.self)
Step 5
Everything should work! All languages should work, no extra methods to call.