【发布时间】:2017-07-01 07:26:56
【问题描述】:
我正在尝试在我的项目中设置 UI 测试。我正在做一个 UI 测试,试图通过我的应用程序登录提示登录。为了确保在测试启动时显示登录提示,我尝试运行项目代码库中的ServerManager.logout()。这将导致在启动时显示登录提示。
import XCTest
class SmokeTest: XCTestCase {
override func setUp() {
super.setUp()
// 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
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
XCUIApplication().launch()
// 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.
ServerManager.logout()
}
func testLogin() {
let app = XCUIApplication()
let emailTextField = app.textFields["email textfield"]
emailTextField.tap()
emailTextField.typeText("test@test.com")
let passwordTextField = app.secureTextFields["password textfield"]
passwordTextField.tap()
passwordTextField.typeText("12345678")
let loginButton = app.buttons["log in button"]
loginButton.tap()
}
}
我应该如何设置我的项目以访问ServerManager?
当我在 ServerManager.swift 文件中检查 UITest 目标(称为 DonkeyProductionUITests)的 Target Membership 时,Xcode 开始抱怨该文件中的许多引用未为 UITest 目标定义。因此,我将项目中所有文件的 Target Membership 添加到 UITest Target,包括所有 CocoaPods。它解决了大多数问题。我还有一些奇怪的剩菜:
UITest 目标应该有哪些源文件作为“编译源”?
为什么 Xcode 突然无法识别 UIColor 和 UIViewController 之类的类型?
【问题讨论】:
标签: ios xcode xctest xcode-ui-testing