3. XCTest
• XCTest is the testing framework in Xcode
• A test method is an instance method of a
test class that begins with the prefix test
- (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
XCTAssert(1+1==2);
XCTAssertTrue(1+1==2);
XCTAssertFalse(1+1==3);
}
• XCTAssert
XCTAssert(expression, …);
XCTAssertTrue(expression, …);
XCTAssertFalse(expression, ...);
9. OCMock
• mock objects are simulated objects that mimic the
behavior of real objects in controlled ways
- (void)testMock {
id mockUserInfo = OCMClassMock([UserInfo class]);
// fullname should be nil for now
XCTAssertNil([mockUserInfo fullname]);
// make a custom return value
OCMStub([mockUserInfo fullname]).andReturn(@"David");
// fullname should be David now
XCTAssert([[mockUserInfo fullname] isEqualToString:@"David"]);
}
10. OCMock Example (1)
ListViewController has a collection view
find all SomeModel from server when viewDidLoad
// in SomeModel.h file
@interface SomeModel : ModelObject
+ (void)findAllByCurrentUserId:(NSString *)currentUserId
completion:(ArrayResultBlock)completion;
@end
18. MVP
• MVP is a derivation of the
MVC architectural pattern
• view can’t retrieve data from
model directly
• low coupling
19. MVP's advantage
• easier to unit test, clean
separation of the View and Model
• maintainability of UI increases
due to almost no dependency on
business logic
• Usually view to presenter map
one to one. Complex views may
have multi presenters
37. benefits of Testing/TDD
• test => spec
• saves you development time
• saves you development time
• Good unit testing forces good
architecture. In order to make your
code unit-testable, it must be properly
modularized, by writing the unit
testing first various architectural
problems tend to surface earlier