Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TDD in Objective-C

TDD in Objective-C

Kartik Patel

March 19, 2015
Tweet

More Decks by Kartik Patel

Other Decks in Programming

Transcript

  1. TOOLS XCTest - testing framework Stubble - mocking framework KIF

    - integration testing framework Fox - property based testing framework
  2. RULES 1. Write new code when a unit test fails

    (mostly) 2. Eliminate duplication
  3. STEPS TO CREATING A CLASS USING TDD 1. Analysis 2.

    Write Test 3. Implement 4. Improve
  4. TEST DOUBLES ▸ Dummy objects are passed around but never

    actually used. ▸ Fake objects actually have working implementations, but usually take some shortcut ▸ Stubs provide canned answers to calls made during the test, may also record information about calls ▸ Mocks are objects pre-programmed with expectations, form a specification of the calls they are expected to receive.
  5. XCTEST REFERENCE #import <XCTest/XCTest.h> #import “TDDStack.h” @interface TDDStackTest : XCTestCase

    @end @implementation TDDStackTest -(void)setUp { ... } /* optional */ -(void)tearDown { ... } /* optional */ -(void)testEmptyAtCreation { TDDStack *stack = [[TDDStack alloc] init]; XCTAssertTrue(stack.isEmpty, @”Not Empty!”); } @end