'Test localized strings from swift package

In my main part of the app we have the localizable.strings file and then we have modularized our app into packages and want to test if a computed property in the viewModel returns the correct string.

The ViewModel:

open class ScheduleHeaderViewModel {
    public var headingLabel: String {
        NSLocalizedString("schedule.header.title", comment: "Heading label")
    }
}

The Test:

class ScheduleHeaderViewModelTests: XCTestCase {
    private let store = AppStoreMock(
        initial: .mock(),
        reducer: AppState.reducer, middlewares: []
    )
    private let device = UIDeviceMock()
    private var viewModel: ScheduleHeaderViewModel!

    override func setUp() {
        viewModel = ScheduleHeaderViewModel(store: store, device: device)
    }

    override func tearDown() {
        store.reset()
        device.reset()
    }


    func testHeadingLabel() {
        XCTAssertEqual(viewModel.headingLabel, "schedule.header.title")
    }
}

The .strings file

"schedule.header.title" = "SCHEDULE";

Currently the test passes but it is returning "schedule.header.title" and should return "SCHEDULE"

Is there a way to do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source