Post

Replies

Boosts

Views

Activity

UISwitch Unit test with sendActions(for: .valueChanged)
GOAL: I'm currently unit testing the behavior of my UISwitch when it is pressed. ISSUE: My issue I that the sendActions(for: .valueChanged) that I use to programmatically change the UISwitch's state is not working as I imagined. It doesn't make it change from false to true (in my example). WHAT DID I DO ?: I'm using the following path: I declared my UISwitch as true I used sendActions(for: .valueChanged) for changing it to false I finally used XCTAssertEqual() to check if it correctly equal to false as expected. (I also could have used XCTAssertFalse() to check directly if it was false. Ps: I correctly passed loadViewIfNeeded() in my setUPWithError() QUESTION: How can I test my UISwitch ?? Maybe using UI Tests ? CODE: Here is my code: var sut: ViewController! override func setUpWithError() throws { super.setUp() let storyboard = UIStoryboard(name: "Main", bundle: nil) sut = storyboard.instantiateViewController(withIdentifier: "ViewController") as? ViewController sut.loadViewIfNeeded() } func testGenderButton_ShouldUpdateValueWhenPressed() { sut.genderSwitch.isOn = true sut.genderSwitch.sendActions(for: .valueChanged) XCTAssertEqual(sut.genderSwitch.isOn, false, "\(sut.genderSwitch.isOn) should be equal to false") }
2
1
1.3k
Mar ’23
UI Test on UISegmented Control
GOAL: I want to UI test my SegmentedControl - check that each segment is selected when tapped on it CONTEXT: The shoeType UISegmentedControl has 3 segments [City, Running, Baskets] CODE: Here is my code: ViewController.swift : @IBOutlet weak var shoeType: UISegmentedControl! ViewControllerUITest.swift: func testSegmentedControl_WhenTapped_ChangeSegment() { app.launch() let shoeTypeSegmentedControl = app.segmentedControls["city"] app.segmentedControls["city"].tap() XCTAssertEqual(shoeTypeSegmentedControl.label, "City") }
1
1
779
Mar ’23
Minor typo issue on Swift Fundamentals in iBooks
Hi, As I was reading the Apple book « Develop in Swift Fundamentals » I found out that: a curly brace was not correctly indented on a code sample - page 184 (see screenshot n1) a print statement result was not shown following an explanation - page 192 (screenshot n2) Anyone knows on how to reach out to Apple in order to fix this ? Thanks 👌🏻 Screenshot 1 : Screenshot 2: (https://books.apple.com/fr/book/develop-in-swift-fundamentals/id1581182804)
2
0
451
Mar ’23