【问题标题】:XCUITest integration with TestRailXCUITest 与 TestRail 的集成
【发布时间】:2019-01-08 09:57:33
【问题描述】:

目前正在努力将我的 UITest 运行结果集成到 TestRail 中,因此在每次测试运行后,它都会在 testrail 中将我的测试标记为 Pass\Fail。

我的想法是:

  1. 在 CI 中创建一个“预构建”脚本,该脚本将在 testrail 中创建一个测试运行。
  2. 在自动化执行期间,在 test tearDown() 中获取测试结果(如果测试失败与否),将其全部保存到 json 文件中。 - 这里是第一个问题,如果测试失败了怎么办?
  3. 完成所有测试后,运行“构建后”脚本以获取更新的 json 文件并将请求发送到测试轨道(这将标记通过\失败测试)

谁已经在这方面工作过,听起来适合你吗? 有什么建议吗?

测试示例:

import XCTest

class MyUITests: XCTestCase {

    override func setUp() {
        super.setUp()
        continueAfterFailure = false
        appEntry.app.launch()
        dismissSystemAlerts()
    }

    override func tearDown() {
        super.tearDown()
    }

    func test_Elements() {
        // MARK: Sample test
        // my test actions are here
    }
}

【问题讨论】:

  • 我已经解决了这个问题,但请提供一些示例代码。
  • 如果我没听错,这就是我的 UITest 的样子(用示例更新了我的问题)

标签: ios swift xctest xcuitest testrail


【解决方案1】:

这就是我的实现方式。 首先,我的 CI 中有预构建脚本,它将在 TestRail 中创建新的测试运行。然后 UITestObserver 会向 TR 发送 API 来更新状态。

我添加的新课程:

import Foundation
import XCTest

class UITestObserver: NSObject, XCTestObservation {
    // Handle Test Case Failure
    public func testCase(_ testCase: XCTestCase,
                         didFailWithDescription description: String,
                         inFile filePath: String?,
                         atLine lineNumber: Int) {
        var testCaseId: [String] = []
        if let MyTestCaseID = testCase as? BaseTest { testCaseId = MyTestCaseID.inegrateTestRailId() }
        if testCaseId != ["NA"] {
            postTestRailAddResultAPI(for: testCase, testCaseId: testCaseId, description: description)
        }
    }

    // Handle Test Case Pass
    public func testCaseDidFinish(_ testCase: XCTestCase) {
        let testRun = testCase.testRun!
        let verb = testRun.hasSucceeded
        var testCaseId: [String] = []
        if let MyTestCaseID = testCase as? BaseTest { testCaseId = MyTestCaseID.inegrateTestRailId() }
        if verb == true && testCaseId != ["NA"] {
            postTestRailAddResultAPI(for: testCase, testCaseId: testCaseId, description: "PASS")
    }
}

在 BaseTest setUp 中添加了这一行:

XCTestObservationCenter.shared.addTestObserver(UITestObserver())

并实现了发送实际请求以更新状态的函数 postTestRailAddResultAPI。 我所有的测试现在都有testCaseId,它存储TestRail TestCase number的值,这就是它知道要更新哪些TC的方式。

【讨论】:

  • 您能否指出我在postTestRailAddResultAPI 中使用了什么的正确方向,或者如果您在某个地方编写了实现,我想看看。提前致谢
【解决方案2】:

这就是我的工作,

  1. 使用 fastlane 的扫描插件运行测试
  2. 生成一个junit格式结果
  3. 解析 xml 并获取每个测试的结果
  4. 将其发布到我们的测试用例管理工具

请与我们所有人分享您的解决方案。

【讨论】:

    猜你喜欢
    • 2019-07-15
    • 2017-09-03
    • 2020-04-25
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多