Add a new screen

Add Tests
This commit is contained in:
2018-07-10 14:22:28 +08:00
parent 65582f0842
commit b81cebe334
12 changed files with 682 additions and 5 deletions

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -0,0 +1,74 @@
import XCTest
@testable import StudyCK
class StudyCKUITests: XCTestCase {
var app: XCUIApplication! = nil
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.
app = XCUIApplication()
app.launch()
// In UI tests its 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.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testEmptyUsernameAndPassword() {
app.buttons["登入"].tap()
let test = expectation(for: NSPredicate(format: "exists == 1"), evaluatedWith: app.alerts["錯誤"], handler: nil)
wait(for: [test], timeout: 10)
XCTAssert(app.alerts["錯誤"].staticTexts["帳號不存在"].exists)
app.alerts["錯誤"].buttons["重試"].tap()
}
func testEmptyUsername() {
app.secureTextFields["passwordField"].tap()
app.secureTextFields["passwordField"].typeText("aa")
app.buttons["登入"].tap()
let test = expectation(for: NSPredicate(format: "exists == 1"), evaluatedWith: app.alerts["錯誤"], handler: nil)
wait(for: [test], timeout: 10)
XCTAssert(app.alerts["錯誤"].staticTexts["帳號不存在"].exists)
}
func testEmptyPassword() {
app.textFields["usernameField"].tap()
app.textFields["usernameField"].typeText("ck1060535")
app.buttons["登入"].tap()
let test = expectation(for: NSPredicate(format: "exists == 1"), evaluatedWith: app.alerts["錯誤"], handler: nil)
wait(for: [test], timeout: 10)
XCTAssert(app.alerts["錯誤"].staticTexts["密碼錯誤,請再試一次"].exists)
}
func testWrongPassword() {
app.textFields["usernameField"].tap()
app.textFields["usernameField"].typeText("ck1060535")
app.secureTextFields["passwordField"].tap()
app.secureTextFields["passwordField"].typeText("aa")
app.buttons["登入"].tap()
let test = expectation(for: NSPredicate(format: "exists == 1"), evaluatedWith: app.alerts["錯誤"], handler: nil)
wait(for: [test], timeout: 10)
XCTAssert(app.alerts["錯誤"].staticTexts["密碼錯誤,請再試一次"].exists)
}
func testLogin() {
app.textFields["usernameField"].tap()
app.textFields["usernameField"].typeText("tUsername")
app.secureTextFields["passwordField"].tap()
app.secureTextFields["passwordField"].typeText("tPassword")
app.buttons["登入"].tap()
expectation(for: NSPredicate(format: "exists == 1"), evaluatedWith: app.navigationBars["choiceController"], handler: nil)
waitForExpectations(timeout: 10, handler: nil)
}
}