XCUITest与TestRail集成

问题描述 投票:3回答:2

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

我的想法是:

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

任何已经参与过这项工作的人,这听起来是否合适?有什么建议?

测试的例子:

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
    }
}
ios swift xctest xcuitest testrail
2个回答
3
投票

这就是我实施的方式。首先,我在我的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的方式。


1
投票

这就是我做的,

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

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

© www.soinside.com 2019 - 2024. All rights reserved.