talks to the database • It communicates across the network • It touches the file system • It can't run at the same time as any of your other unit tests • You have to do special things to your environment (such as editing config files) to run it.
automated • Tests a single logical concept in the system • Consistently returns the same result • Maintainable and order-independent • Independent • Runs fast • Readable • Trustworthy
automatically include a unit testing target • Test classes do not have a header file • It’s not necessary to add application’s source files to the XCTest Target
automatically include a unit testing target • Test classes do not have a header file • It’s not necessary to add application’s source files to the XCTest Target • Each test case is a method with prefix test
automatically include a unit testing target • Test classes do not have a header file • It’s not necessary to add application’s source files to the XCTest Target • Each test case is a method with prefix test • Since Xcode 5 allows to run tests from the editor
[super setUp]; // This method is called before the invocation of each test method in the class. } - (void)tearDown { // This method is called after the invocation of each test method in the class. [super tearDown]; } - (void)testExample { XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); }
collaborators of the system under test so that the test is independent of the implementation of the collaborators. Mock Object Behaviour Verification SUT Setup Exercise Verify Tear Down Behaviour (Indirect Outputs) DOC
collaborators of the system under test so that the test is independent of the implementation of the collaborators. Mock Object Behaviour Verification SUT Setup Exercise Verify Tear Down Behaviour (Indirect Outputs) Fake
collaborators of the system under test so that the test is independent of the implementation of the collaborators. Mock Object SUT Behaviour Verification Setup Exercise Verify Tear Down Behaviour (Indirect Outputs) Fake Verify
as if it were an instance of // SomeClass. id mock = [OCMockObject mockForClass:[SomeClass class]]; // Tells the mock object that someMethod: should be called with an argument // that is equal to someArgument. [[mock expect] someMethod:someArgument]; // After this setup the functionality under test should be invoked // followed by [mock verify]; // When a method is called on a mock object that has not been set up with // either expect or stub the mock object will raise an exception. This // fail-fast mode can be turned off by creating a "nice" mock: id mock = [OCMockObject niceMockForClass:[SomeClass class]]; // While nice mocks will simply ignore all unexpected methods it is // possible to disallow specific methods: [[mock reject] someMethod];
called with // someArgument it should return aValue. [[[mock stub] andReturn:aValue] someMethod:someArgument]; // It is not possible to pass primitive types directly. [[[mock stub] andReturnValue:@YES] aMethodReturnABoolean:someArgument]; // The mock object can also throw an exception or post a notification // when a method is called [[[mock stub] andThrow:anException] someMethod:someArgument]; [[[mock stub] andPost:aNotification] someMethod:someArgument]; // If Objective-C blocks are available a block can be used to handle the // invocation and set up a return value void (^theBlock)(NSInvocation *) = ^(NSInvocation *invocation) { /* code that reads and modifies the invocation object */ }; [[[mock stub] andDo:theBlock] someMethod:[OCMArg any]];
for a specific instance. - (id<AspectToken>)aspect_hookSelector:(SEL)selector withOptions:(AspectOptions)options usingBlock:(id)block error:(NSError **)error; /// Called after the original implementation (default) AspectPositionAfter, /// Will replace the original implementation. AspectPositionInstead, /// Called before the original implementation. AspectPositionBefore, Aspects