Skip to content

Commit 328c296

Browse files
Add basic UI tests
1 parent 81d9ee0 commit 328c296

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

SwiftWeather/WeatherViewController.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class WeatherViewController: UIViewController {
2323
super.viewDidLoad()
2424
viewModel = WeatherViewModel()
2525
viewModel?.startLocationService()
26+
setA11yIdentifiers()
2627
}
2728

2829
override func viewWillAppear(_ animated: Bool) {
@@ -108,4 +109,13 @@ class WeatherViewController: UIViewController {
108109
}
109110
}
110111
}
111-
}
112+
113+
//MARK: Accessibility
114+
func setA11yIdentifiers() {
115+
locationLabel.accessibilityIdentifier = "a11y_current_city"
116+
iconLabel.accessibilityIdentifier = "a11y_wheather_icon"
117+
temperatureLabel.accessibilityIdentifier = "a11y_wheather_temperature"
118+
}
119+
120+
121+
}

SwiftWeatherUITests/SwiftWeatherUITests.swift

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,33 @@
44
//
55

66
import XCTest
7+
import Quick
8+
import Nimble
79

8-
class SwiftWeatherUITests: XCTestCase {
10+
class SwiftWeatherUITests: QuickSpec {
911

10-
override func setUp() {
11-
super.setUp()
12-
13-
// Put setup code here. This method is called before the invocation of each test method in
14-
// the class.
15-
16-
// In UI tests it is usually best to stop immediately when a failure occurs.
17-
continueAfterFailure = false
18-
// UI tests must launch the application that they test. Doing this in setup will make sure
19-
// it happens for each test method.
20-
XCUIApplication().launch()
21-
}
22-
23-
override func tearDown() {
24-
// Put teardown code here. This method is called after the invocation of each test method
25-
// in the class.
26-
super.tearDown()
27-
}
28-
29-
func testApp() {
12+
override func spec() {
3013
let app = XCUIApplication()
31-
testNumberOfElements(app)
32-
}
3314

34-
/* Actually test that images load...might want to find a more exact way of doing this... */
35-
func testNumberOfElements(_ app: XCUIApplication) {
36-
assert(app.staticTexts.count > 0)
15+
beforeSuite {
16+
self.continueAfterFailure = false
17+
XCUIDevice.shared().orientation = .portrait
18+
app.launch()
19+
}
20+
21+
describe("a wheather viewcontroller") {
22+
it("shows city") {
23+
expect(app.staticTexts["a11y_current_city"].exists).to(beTruthy())
24+
}
25+
26+
it("shows wheather icon") {
27+
expect(app.staticTexts["a11y_wheather_icon"].exists).to(beTruthy())
28+
}
29+
30+
it("shows wheather temperature") {
31+
expect(app.staticTexts["a11y_wheather_temperature"].exists).to(beTruthy())
32+
}
33+
}
3734
}
3835

3936
}

0 commit comments

Comments
 (0)