如何在 iOS XCTest 单元测试中测试从右到左的语言? [英] How to test right-to-left language in iOS XCTest unit tests?

查看:41
本文介绍了如何在 iOS XCTest 单元测试中测试从右到左的语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将 XCTest 单元测试切换到从右到左模式来测试应用程序的阿拉伯语版本,其中句子从屏幕的右到左书写?我的应用程序代码逻辑根据语言方向表现不同.我想在单元测试中验证此功能.我需要做的是将应用程序从 XCTest 单元测试用例切换到从右到左的语言模式.

Is there a way to switch an XCTest unit test into the right-to-left mode to test Arabic version of the app where sentences are written from right to left of the screen? My app code logic behaves differently based on language direction. I would like to verify this functionality in a unit test. What I need to do is to switch the app into the right-to-left language mode from an XCTest unit test case.

通过将 Scheme 的应用程序语言设置更改为从右到左伪语言,可以在从右到左模式下运行应用程序.有没有办法在单元测试中做类似的事情?

One can run the app in the right-to-left mode by changing the Scheme's Application language settings to Right-to-left Pseudolanguage. Is there a way to do similar thing in a unit test?

我最终将被测视图的 semanticContentAttribute 更改为 .ForceRightToLeft.它做我需要做的事情.不过,这感觉并不是一个非常干净的方法.首先,它仅适用于 iOS 9.其次,看起来我正在从单元测试中修改我的应用程序视图.相反,如果可能的话,我更愿意将整个应用程序的语言切换为从右到左.

I ended up changing semanticContentAttribute of a view under test to .ForceRightToLeft. It does what I need to do. It does not feel like a very clean approach though. Firstly, it only works in iOS 9. Secondly, it looks like I am tinkering with my app views on a low level from the unit test. Instead, I would prefer to switch the whole app's language to right-to-left if it is possible.

class MyTests: XCTestCase {
  func testRightToLeft() {
    if #available(iOS 9.0, *) {
      let view = UIView()
      view.semanticContentAttribute = .ForceRightToLeft
      // Test code involving the view
    }
  }
}

推荐答案

除了传入环境标志或设置 semanticContentAttribute 之外,现在没有简单的方法可以通过测试/UI 测试来做到这一点现在在做.强烈建议向 Apple 提交错误.

There's no easy way to do this right now with testing/UI testing besides passing in environment flags or setting the semanticContentAttribute as you are doing now. Filing a bug to Apple is highly recommended.

这篇关于如何在 iOS XCTest 单元测试中测试从右到左的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆