???????Nimble????expect
????Quick?е?????????????????鷳????expect??д????????????Nimble???????
????Nimble?????? expect(...).to ?? expect(...).notTo??д?????磺
????expect(seagull.squawk).to(equal("Oh?? hello there!"))
????expect(seagull.squawk).notTo(equal("Oh?? hello there!"))
????Nimble??????????????????????д:
????dispatch_async(dispatch_get_main_queue()) {
????ocean.add("dolphins")
????ocean.add("whales")
????}
????expect(ocean).toEventually(contain("dolphins")?? timeout: 3)
??????????????waitUntil?????е????
????waitUntil { done in
????// do some stuff that takes a while...
????NSThread.sleepForTimeInterval(0.5)
????done()
????}
????????????о?Nimble?е???亯????
????????ж?
???????equal????????:
????expect(actual).to(equal(expected))
????expect(actual) == expected
????expect(actual) != expected
???????????????
???????beIdenticalTo????
????expect(actual).to(beIdenticalTo(expected))
????expect(actual) === expected
????expect(actual) !== expected
???????
????expect(actual).to(beLessThan(expected))
????expect(actual) < expected
????expect(actual).to(beLessThanOrEqualTo(expected))
????expect(actual) <= expected
????expect(actual).to(beGreaterThan(expected))
????expect(actual) > expected
????expect(actual).to(beGreaterThanOrEqualTo(expected))
????expect(actual) >= expected
?????????????????????????????:
????expect(10.01).to(beCloseTo(10?? within: 0.1))
??????????
????expect(instance).to(beAnInstanceOf(aClass))
????expect(instance).to(beAKindOf(aClass))
??????????
????// Passes if actual is not nil?? true?? or an object with a boolean value of true:
????expect(actual).to(beTruthy())
????// Passes if actual is only true (not nil or an object conforming to BooleanType true):
????expect(actual).to(beTrue())
????// Passes if actual is nil?? false?? or an object with a boolean value of false:
????expect(actual).to(beFalsy())
????// Passes if actual is only false (not nil or an object conforming to BooleanType false):
????expect(actual).to(beFalse())
????// Passes if actual is nil:
????expect(actual).to(beNil())
???????????
????// Passes if actual?? when evaluated?? raises an exception:
????expect(actual).to(raiseException())
????// Passes if actual raises an exception with the given name:
????expect(actual).to(raiseException(named: name))
????// Passes if actual raises an exception with the given name and reason:
????expect(actual).to(raiseException(named: name?? reason: reason))
????// Passes if actual raises an exception and it passes expectations in the block
????// (in this case?? if name begins with 'a r')
????expect { exception.raise() }.to(raiseException { (exception: NSException) in
????expect(exception.name).to(beginWith("a r"))
????})
??????????
????// Passes if all of the expected values are members of actual:
????expect(actual).to(contain(expected...))
????expect(["whale"?? "dolphin"?? "starfish"]).to(contain("dolphin"?? "starfish"))
????// Passes if actual is an empty collection (it contains no elements):
????expect(actual).to(beEmpty())
?????????
????// Passes if actual contains substring expected:
????expect(actual).to(contain(expected))
????// Passes if actual begins with substring:
????expect(actual).to(beginWith(expected))
????// Passes if actual ends with substring:
????expect(actual).to(endWith(expected))
????// Passes if actual is an empty string?? "":
????expect(actual).to(beEmpty())
????// Passes if actual matches the regular expression defined in expected:
????expect(actual).to(match(expected))
??????鼯???е??????????????????
????// with a custom function:
????expect([1??2??3??4]).to(allPass({$0 < 5}))
????// with another matcher:
????expect([1??2??3??4]).to(allPass(beLessThan(5)))
??????鼯?????
????expect(actual).to(haveCount(expected))
????????????????
????// passes if actual is either less than 10 or greater than 20
????expect(actual).to(satisfyAnyOf(beLessThan(10)?? beGreaterThan(20)))
????// can include any number of matchers -- the following will pass
????expect(6).to(satisfyAnyOf(equal(2)?? equal(3)?? equal(4)?? equal(5)?? equal(6)?? equal(7)))
????// in Swift you also have the option to use the || operator to achieve a similar function
????expect(82).to(beLessThan(50) || beGreaterThan(80))
????????UIViewController
????????UIViewController?????????е????
????· ???? UIViewController.view?? ?????? UIViewController.viewDidLoad()??
????· ???? UIViewController.beginAppearanceTransition() ???????????????
????· ???????????????е????
???????????UIControl Events
????describe("the 'more bananas' button") {
????it("increments the banana count label when tapped") {
????viewController.moreButton.sendActionsForControlEvents(
????UIControlEvents.TouchUpInside)
????expect(viewController.bananaCountLabel.text).to(equal("1"))
????}
????}
????????
??????????? ?ο?????5?е?????????????Quick????д???????
???????????????????????????????+???????????У????????????????????????????????б??У??????浽CoreData?С?

?????????????Massive ViewController???????tableView??DataSource???????????PeopleListDataProvider????????????С?????????????????????????PeopleListViewController??????У?????????????????????PeopleListDataProvider??addPerson???????????CoreData?У????????檔
??????????addPerson?????????????Mock???DataProvider????????м????????????????addPerson?????ú???????????addPersonGotCalled?????????£?
????class MockDataProvider: NSObject?? PeopleListDataProviderProtocol {
????var addPersonGotCalled = false
????var managedObjectContext: NSManagedObjectContext?
????weak var tableView: UITableView?
????func addPerson(personInfo: PersonInfo) { addPersonGotCalled = true }
????func fetch() { }
????func tableView(tableView: UITableView?? numberOfRowsInSection section: Int) -> Int { return 1 }
????func tableView(tableView: UITableView?? cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { return UITableViewCell() }
????}
??????????????????????????????provider?з??????????:
????context("add person") {
????it("provider should call addPerson") {
????let record: ABRecord = ABPersonCreate().takeRetainedValue()
????ABRecordSetValue(record?? kABPersonFirstNameProperty?? "TestFirstname"?? nil)
????ABRecordSetValue(record?? kABPersonLastNameProperty?? "TestLastname"?? nil)
????ABRecordSetValue(record?? kABPersonBirthdayProperty?? NSDate()?? nil)
????viewController.peoplePickerNavigationController(ABPeoplePickerNavigationController()?? didSelectPerson: record)
????expect(provider.addPersonGotCalled).to(beTruthy())
????}
????}
?????????????????????ViewController??????????棬???????????????dataProvider????????provider??addPerson????ViewController?е?tableView?????????????????????????α?????????
context("add one person") {
beforeEach {
dataProvider.addPerson(testRecord)
}
it("section should be 1") {
expect(tableView.dataSource!.numberOfSectionsInTableView!(tableView)) == 1
}
it("row should be 1") {
expect(tableView.dataSource!.tableView(tableView?? numberOfRowsInSection: 0)) == 1
}
it("cell show full name") {
let cell = tableView.dataSource!.tableView(tableView?? cellForRowAtIndexPath: NSIndexPath(forRow: 0?? inSection: 0)) as UITableViewCell
expect(cell.textLabel?.text) == "TestFirstName TestLastName"
}
}
??????????????????demo??
????????
???????????
??????????swift???objc?????????????????????????????????????????????????е?objc???????????????????С??ο?????python???:
import os
excludeKey = ['Pod'??'SBJson'??'JsonKit']
def filterFunc(fileName):
for key in excludeKey:
if fileName.find(key) != -1:
return False
return True
def mapFunc(fileName):
return '#import "%s"' % os.path.basename(fileName)
fs = []
for root?? dirs?? files in os.walk("."):
for nf in [root+os.sep+f for f in files if f.find('.h')>0]:
fs.append(nf)
fs = filter(filterFunc?? fs)
fs = map(mapFunc?? fs)
print " ".join(fs)
???????????????target
???????????unit test????????target?????????????????????????????飬???ò??????????????target??????target????Info.plist????????????????е?Info.plist??bundle name?UnitTest?????????????????????ж??
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *value = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleName"];
if ([value isEqualToString:@"UnitTest"]) {
return YES; // ???????????
}
// ???????...
}