首页 > 解决方案 > 如何将标签/属性添加到 XCUITest(Swift)

问题描述

我想弄清楚我们是否有任何方法可以将标记/属性设置为 Swift 中的测试。在 C# 中,我们使用基于功能和测试类型来标记测试,以帮助我们进行报告。以下是示例:-

[Category("LongRunning"),Category("Workspace")] 公共类 LongRunningTests { ... }

任何帮助表示赞赏。

标签: iosswiftautomated-testsxcuitest

解决方案


Swift 中没有内置选项可以不注释测试用例和测试类。

您应在自定义 XCTestCase 中添加包含测试名称及其组的 Dictionary,并基于此 Dictionary 覆盖 invokeTest()。

您的注释可能如下所示:

class TestClass: CustomUITestCase {

    override var testClassesGrouping: [TestClassesGroups] { return  [.positiveScenarios] }
    override var testCasesGrouping: [String: [TestCasesGroups]] { return
        ["testReminderWithNotes": [.testSettingNotes],
         "testPastReminder": [.testChangingDate],
         "testFutureReminder": [.testChangingDate],
         "testFuturePrioritised": [.testChangingDate, .testSettingPriority],
         "testPrioritisedReminder": [.testSettingPriority]]
    }
    ... 
}

推荐阅读