Maurice Kelly presents two popular test frameworks that serve as alternatives to Apple's XCUnit. As part of his role in ShopKeep, Maurice uses the frameworks extensively and shows how they can enhance your code quality.
When an action is taken Then a result occurs Given the same system When a second action is taken Then a second result occurs Given the same system With a subtle adjustment When a third action is taken Then a third result occurs
an action is taken it - causes a result to occur describe - a second action is taken it - causes a second result to occur context - the system is adjusted describe - a third action is taken it - causes a third result to occur
state", ^{ describe(@"an action is taken", ^{ it(@"causes a result to occur", ^{ }); }); describe(@"a second action is taken", ^{ it(@"causes a second result", ^{ }); }); context(@"and the system is adjusted", ^{ describe(@"a third action is taken", ^{ it(@"causes a third result", ^{ }); }); }); });
and protocols • Null mocks can receive any message without complaining • Plain mocks throw exceptions when receiving a message that isn't stubbed • Stubs • Adds ability to receive and handle specific messages • Can parse the message parameters • Can return values
has a specific state", ^{ describe(@"an action is taken", ^{ it(@"causes a result to occur", ^{ }); }); }); SPEC_END • Create a test class and enter a spec
the app is launched", ^{ it(@"displays a welcome message", ^{ [tester waitForViewWithAccessibilityLabel:@"Welcome to Kiwi and KIF"]; }); it(@"shows a switcheroo button", ^{ [tester waitForViewWithAccessibilityLabel:@"Switcheroo" traits:UIAccessibilityTraitButton]; }); describe(@"the button is pressed", ^{ beforeEach(^{ [tester tapViewWithAccessibilityLabel:@"Switcheroo" traits:UIAccessibilityTraitButton]; }); it(@"updates the welcome label", ^{ [tester waitForViewWithAccessibilityLabel:@"Or is it KIF and Kiwi?"]; }); }); }); SPEC_END