【问题标题】:iOS Run UITesting in sequence (file and function level)iOS 按顺序运行 UITesting(文件和函数级别)
【发布时间】:2023-03-21 12:40:02
【问题描述】:

我已经创建了这样的 UITesting。我需要依次运行这 3 个文件,我需要这样命名。我认为这很糟糕。我想更合乎逻辑地命名(而不是 Test1 等)。是否可以重命名并按顺序运行?

另一个是我需要按字母顺序命名我的方法。我想随机命名并按顺序运行。我该怎么办?

- (void)test2CreatePost 
- (void)test3ClickLikeInNewsfeed

【问题讨论】:

    标签: ios xcode-ui-testing


    【解决方案1】:

    您可以使用此答案中解释的过程来实现此目的。

    Running individual XCTest (UI, Unit) test cases for iOS apps from the command line

    基本上,您需要覆盖 XCTestCase 中的 testInvocations,然后您可以控制测试用例的执行顺序。

    如果您需要有关如何实现此功能的更多信息,请添加评论。

    【讨论】:

    • 让我看看。
    【解决方案2】:

    您可以通过嵌套函数来实现这一点。

    // Note that this function contains tests but does not follow the 'testXXX' naming convention
    func login() {
        // Implement your test here
    }
    
    func newsfeed() {
        // Implement your test here
    }
    
    func moreTab() {
        // Implement your test here
    }
    
    // Here is the test method that will run the tests in a user-specified order
    func testSomething() {
        login()
        newsfeed()
        moreTab()
    }
    

    【讨论】:

    • 嗯。看起来不错。但是当xCode生成报告时,它只会说testSomething是否成功。
    【解决方案3】:

    函数嵌套仅适用于从 XCode 即时运行 UI 测试。但是当测试从命令行运行时,它们是按字母顺序运行的。我读过这个问题已在 XCode 8 中的单元测试中得到修复,但似乎不适用于 UI 测试。

    例如,现在我有以下 UI 测试层次结构:

    UITests
       TestCaseB
       TestCaseA
    

    当我从 XCode 8.2.1 运行它们时,它们的执行顺序与描述的相同,即:

    TestCaseB
    TestCaseA
    

    但是当我使用xcodebuild test TEST_TARGET_NAME=<TargetName> -scheme <UITestsSchemeName> destination 'platform=iOS Simulator,name=iPhone 7' 从命令行运行它们时,它们会以另一个顺序运行:

    TestCaseA
    TestCaseB
    

    小心点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2019-08-09
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多