ButtonTap
iOS Unit Testing by Example – Chapter 8
@testable import ButtonTap
import XCTest
class ViewControllerTests: XCTestCase {
func test_tappingButton() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let sut: ViewController = storyboard.instantiateViewController(identifier: String(describing: ViewController.self))
sut.loadViewIfNeeded()
tap(sut.button)
}
}
import UIKit
func tap(_ button: UIButton) {
button.sendActions(for: .touchUpInside)
}
func tap(_ button: UIBarButtonItem) {
_ = button.target?.perform(button.action, with: nil)
}