Search code examples
swiftxcode-ui-testingswift-snapshot-testing

Change region in UI testing for each case


i am using swift-snapshot-testing library to do snapshot testing. It's important for me to do all the tests with different localization to check all the UIs when the text is changed. For example, the UI testing scheme is set to run on German language and region, In some tests, I want to see the english version as well and I did that

class BackgroundViewFactoryTests: XCTestCase {
    
    override class func setUp() {
        SnapshotTesting.diffTool = "ksdiff"
    }
    
    func test_backgroundView_contact_eng() {

        
        continueAfterFailure = false

        XCUIApplication().launchArguments += ["-AppleLanguages", "(en)"]

        XCUIApplication().launchArguments += ["-AppleLocale", "en_UK"]

        XCUIApplication().launch()
        
        let view = BackgroundViewFactory()
        view.backgroundColor = .darkGray
        assertSnapshot(matching: view, as: .image, record: false)
        
    }
}

But it's still not working and run on German language, could anyone give me hit? Thanks


Solution

  • The snapshot tests should be agnostic to all Strings. You don’t want breaking tests if you change one translation. Test the translation in a separate UnitTest.