You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import XCTest
finalclassDJKAdvancedLearning_UITests:XCTestCase{
//把app的创建提取出来
letapp=XCUIApplication()overridefunc setUpWithError()throws{
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure =false
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
//初始化创建
app.launch()}overridefunc tearDownWithError()throws{
// Put teardown code here. This method is called after the invocation of each test method in the class.
}func testExample()throws{
// UI tests must launch the application that they test.
//不需要每个测试都去初始化一遍,直接用全局的app
// let app = XCUIApplication()
// app.launch()
// Use XCTAssert and related functions to verify your tests produce the correct results.
}func testLaunchPerformance()throws{if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0,*){
// This measures how long it takes to launch your application.
measure(metrics:[XCTApplicationLaunchMetric()]){XCUIApplication().launch()}}}}
TextField(vm.placeFolder, text: “Add Your Name”).font(.headline).padding().background(Color.white).cornerRadius(10).accessibilityIdentifier("SignUpTextField")
测试使用:
// let addYourNameTextField = app.textFields["Add Your Name"]
letaddYourNameTextField= app.textFields["SignUpTextField"]
Swift中的UITest
UITest和UnitTest又完全不一样了,UITest可以测试用户的界面流程。而不会去测试所有的代码逻辑。
实现
创建步骤
和UnitTest一样在我们的要测试项目中
File->New->Targer->UnitTest Bundle->命名为(项目名_UITest)->Finish
初始Test文件
这里和UnitTest不一样的地方在于,不需要每个测试都去创建Application,只要在初始化的时候创建一次。
命名规则
这里参考UnitTest一样
编写用例
这里的代码是我通过XCode自带的模拟器操作来自动编写出来的,然后再自己修改这个用例,这个是原始的,操作如下:
2022-12-21.14.50.08.mov
修改后的例子
一些小技巧
在Product->Scheme->Edit Scheme -> Run或者在选择ios模拟器的旁边也有这个选项。具体也可以看这里
参考资料
The text was updated successfully, but these errors were encountered: