我正在运行一堆 XCUItests 作为 Fastlane 作业。每次某些测试都会失败并出现错误“无法终止 com.****.****:57929”。
当我在模拟器上直接使用 Xcode 运行这些测试时,效果很好。仅当我在模拟器上使用 Fastlane 运行这些测试时才会出现问题。失败发生在不同时间的不同测试中。以下是示例代码:
class ExampleTests: XCTestCase {
var app: XCUIApplication!
override func setUp() {
super.setUp()
app = XCUIApplication()
continueAfterFailure = false
}
override func tearDown() {
super.tearDown()
}
func testCase1() {
app.launch()
/* Test steps1
step 2
*/
}
func testCase2() {
app.launch()
/* Test steps1
step 2
*/
}
当测试执行 app.launch() 时,它会尝试终止前一个应用程序实例,这就是它失败的地方。有办法解决这个问题吗?非常感谢任何帮助。
在
tearDown()
方法中添加以下代码app.terminate()
。每次运行新的测试用例时,它都会终止您的应用程序实例。