[英]Swift UITest handle starting of all tests and finishing of all test cases
使用 XCTest 编写 UITest 时,我想处理“开始所有测试”和“完成所有测试”。 我想在测试用例之前“注册”用户并在所有测试用例之后删除帐户。我不能使用计数器值整数,因为毕竟测试用例它会重置。 我怎么能处理这个“开始 - 完成”?
这一切都在 Apple 文档中进行了描述。 你想特别使用 setUp 和 tearDown 。
class SetUpAndTearDownExampleTestCase: XCTestCase {
override class func setUp() { // 1.
super.setUp()
// This is the setUp() class method.
// It is called before the first test method begins.
// Set up any overall initial state here.
}
override func setUp() { // 2.
super.setUp()
// This is the setUp() instance method.
// It is called before each test method begins.
// Set up any per-test state here.
}
func testMethod1() { // 3.
// This is the first test method.
// Your testing code goes here.
addTeardownBlock { // 4.
// Called when testMethod1() ends.
}
}
func testMethod2() { // 5.
// This is the second test method.
// Your testing code goes here.
addTeardownBlock { // 6.
// Called when testMethod2() ends.
}
addTeardownBlock { // 7.
// Called when testMethod2() ends.
}
}
override func tearDown() { // 8.
// This is the tearDown() instance method.
// It is called after each test method completes.
// Perform any per-test cleanup here.
super.tearDown()
}
override class func tearDown() { // 9.
// This is the tearDown() class method.
// It is called after all test methods complete.
// Perform any overall cleanup here.
super.tearDown()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.