Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccabanero/ed9111e472f6cb283ff8c3e714712efa to your computer and use it in GitHub Desktop.
Save ccabanero/ed9111e472f6cb283ff8c3e714712efa to your computer and use it in GitHub Desktop.
Sample Unit Tests: Testing UIRightBarButtonItem has correct custom UIImage when toggled
class ViewControllerTest: XCTestCase {
var systemUnderTest: ViewController!
override func setUp() {
super.setUp()
//get the storyboard the ViewController under test is inside
let storyboard: UIStoryboard = UIStoryboard(name: "Main_iPhone", bundle: nil)
//get the ViewController we want to test from the storyboard (note the identifier is the id explicitly set in the identity inspector)
systemUnderTest = storyboard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
//load view hierarchy
_ = systemUnderTest.view
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testSUT_HasRightBarButtonImage_WithCorrectDefaultCustomImage() {
let defaultImage = systemUnderTest.dropDownButton.image
XCTAssert(defaultImage == UIImage(named: "Arrow_down"))
}
func testSUT_HasRightBarButtonImage_WithCorrectCustomImageAfterToggle() {
// invoke action method of rightbarbuttonitem - which toggles the image
//systemUnderTest.performSelector(#selector(systemUnderTest.toggleRightBarButtonItemImage))
systemUnderTest.toggleRightBarButtonItemImage(UIButton())
let rightBarButtonImage = systemUnderTest.dropDownButton.image
XCTAssert(rightBarButtonImage == UIImage(named: "Arrow_up"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment