目前正致力于将我的UITest运行结果集成到TestRail中,因此在每次测试运行后,它都将我的测试标记为testrail中的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
}
}
这就是我实施的方式。首先,我在我的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的方式。
这就是我做的,
请与我们所有人分享您的解决方案。