I've created a successful unit test that checks for an IBAction in Swift. However, the form isn't great:
func testAddButtonIBActionShouldExist() {
let actions=viewController.addButton.actionsForTarget(viewController, forControlEvent: UIControlEvents.TouchUpInside)
XCTAssertNotNil(actions, "Add button should have conections")
if actions != nil{
let actionsAsNSArray:NSArray=actions! as NSArray
XCTAssertTrue(actionsAsNSArray.containsObject("addNumbers:"), "Add button not connected to correct IBAction")
}
}
It separates the test for nil and the containsObject
into two separate parts, and also includes an if
… both of which I believe are bad unit testing form. Is there a way to somehow combine these in Swift 1.2 (or Swift 2)? Thanks for reading.
Aucun commentaire:
Enregistrer un commentaire