SlideShare a Scribd company logo
1 of 82
Download to read offline
Does it work?
I’m not here to convince you
Dry and easy to maintain
Better form of documentation
Protect
Tdd?
Tdd?

Test-driven development (TDD) is a
software development technique that relies
on the repetition of a very short development
cycle




                                http://en.wikipedia.org/wiki/Test-driven_development
Tdd?



first the developer writes a failing automated
test case that defines a desired improvement
or new function




                                 http://en.wikipedia.org/wiki/Test-driven_development
Tdd?




then produces code to pass that test




                            http://en.wikipedia.org/wiki/Test-driven_development
Tdd?



and finally refactors the new code to
acceptable standard




                            http://en.wikipedia.org/wiki/Test-driven_development
Unit Tests?




A test is not a unit test if:


                       Michael Feathers
Unit Tests?




It talks to a database


                    Michael Feathers
Unit Tests?



It communicates across
the network

                     Michael Feathers
Unit Tests?




It touches the file system


                      Michael Feathers
Unit Tests?


You have to do things to
your environment to run
it (eg, change config files)

                       Michael Feathers
Unit Tests?



Tests that do this are
integration tests

                       Michael Feathers
Automatic Testing Lifecycle

   Steps
Fixture Setup
Automatic Testing Lifecycle

   Steps
Fixture Setup
                       SUT
Exercise SUT
Automatic Testing Lifecycle

   Steps
Fixture Setup
                       SUT
Exercise SUT

Verify Result
Automatic Testing Lifecycle

     Steps
  Fixture Setup

  Exercise SUT

  Verify Result

Fixture TearDown
What about iPhone Dev?
Unit Testing for iPhone
Former SenTestingKit



        OCUnit
TestCase definition


#import <SenTestingKit/SenTestingKit.h>
#import "RpnCalculator.h"

@interface RpnCalculatorTestCase : SenTestCase {
! RpnCalculator* rpnCalculator;
}

@end
TestCase definition


#import <SenTestingKit/SenTestingKit.h>
#import "RpnCalculator.h"

@interface RpnCalculatorTestCase : SenTestCase {
! RpnCalculator* rpnCalculator;
}

@end
TestCase Implementation

@implementation RpnCalculatorTestCase

-(void)setUp{
! rpnCalculator = [[RpnCalculator alloc]init];
}

-(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{
! [rpnCalculator put:@"1"];
! [rpnCalculator put:@"enter"];
! [rpnCalculator put:@"2"];!
!
! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil);
}

-(void)tearDown{
  [rpnCalculator release];
}
Fixture Setup

@implementation RpnCalculatorTestCase

-(void)setUp{
! rpnCalculator = [[RpnCalculator alloc]init];
}

-(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{
! [rpnCalculator put:@"1"];
! [rpnCalculator put:@"enter"];
! [rpnCalculator put:@"2"];!
!
! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil);
}

-(void)tearDown{
  [rpnCalculator release];
}
Exercise SUT

@implementation RpnCalculatorTestCase

-(void)setUp{
! rpnCalculator = [[RpnCalculator alloc]init];
}

-(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{
! [rpnCalculator put:@"1"];
! [rpnCalculator put:@"enter"];
! [rpnCalculator put:@"2"];!
!
! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil);
}

-(void)tearDown{
  [rpnCalculator release];
}
Verify Result

@implementation RpnCalculatorTestCase

-(void)setUp{
! rpnCalculator = [[RpnCalculator alloc]init];
}

-(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{
! [rpnCalculator put:@"1"];
! [rpnCalculator put:@"enter"];
! [rpnCalculator put:@"2"];!
!
! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil);
}

-(void)tearDown{
  [rpnCalculator release];
}
Fixture Teardown

@implementation RpnCalculatorTestCase

-(void)setUp{
! rpnCalculator = [[RpnCalculator alloc]init];
}

-(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{
! [rpnCalculator put:@"1"];
! [rpnCalculator put:@"enter"];
! [rpnCalculator put:@"2"];!
!
! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil);
}

-(void)tearDown{
  [rpnCalculator release];
}
Assertions

#define   STAssertNil(a1, description, ...)
#define   STAssertNotNil(a1, description, ...)
#define   STAssertTrue(expression, description, ...)
#define   STAssertFalse(expression, description, ...)
#define   STAssertEqualObjects(a1, a2, description, ...)
#define   STAssertEquals(a1, a2, description, ...)
#define   STFail(description, ...)
#define   STAssertTrueNoThrow(expression, description, ...)
#define   STAssertFalseNoThrow(expression, description, ...)

//....
Xcode integration
Xcode integration
Presentation separate from logic
Presentation separate from logic
Presentation
Logic
Test
Xcode integration
Xcode integration
What if I have to access network...
Or I have correlated components..
Mock it!
Mock it!



[...] mock objects are
simulated objects that mimic
the behavior of real objects
in controlled ways
OCMock




http://www.mulle-kybernetik.com/software/OCMock/
Stubs vs Mocks
                     Mocks



Stubs
Stub



- (void)testReturnsStubbedReturnValue
{
!   mock = [OCMockObject mockForClass:[NSString class]];

    [[[mock stub] andReturn:@"megamock"] lowercaseString];
    id returnValue = [mock lowercaseString];
!
    STAssertEqualObjects(@"megamock", returnValue, nil);
}
Collaboration
                    SOAPMessage
                     XMLString

SOAPClient
   send

                    SOAPChannel
                          post
Collaboration
                    SOAPMessage
                     XMLString

SOAPClient
   send

                    SOAPChannel
                          post
Collaboration
                    SOAPMessage
                     XMLString

SOAPClient
   send

                    SOAPChannel
                          post
Mock

static const NSString * RawSOAPMessage = @"<ENV:evn
xmlns:ENV="http://www.w3.org/....

- (void)testClientShouldSendMessage{
! id msgMock = [OCMockObject mockForClass:[SOAPMessage class]];
! [[[msgMock expect] andReturn:RawSOAPMessage] XMLString];

! id channelMock = [OCMockObject mockForClass:[SOAPChannel class]];
! [[[channelMock expect] andReturn:TRUE] send];

! SOAPClient *client = [SOAPClient initWith:channelMock];
!
! [client sendMessage:msgMock];

! [msgMock verify];
! [channelMock verify];
}
Mockery

static const NSString * RawSOAPMessage = @"<ENV:evn
xmlns:ENV="http://www.w3.org/....

- (void)testClientShouldSendMessage{
! id msgMock = [OCMockObject mockForClass:[SOAPMessage class]];
! [[[msgMock expect] andReturn:RawSOAPMessage] XMLString];

! id channelMock = [OCMockObject mockForClass:[SOAPChannel class]];
! [[[channelMock expect] andReturn:TRUE] send];

! SOAPClient *client = [SOAPClient initWith:channelMock];
!
! [client sendMessage:msgMock];

! [msgMock verify];
! [channelMock verify];
}
Exercise SUT

static const NSString * RawSOAPMessage = @"<ENV:evn
xmlns:ENV="http://www.w3.org/....

- (void)testClientShouldSendMessage{
! id msgMock = [OCMockObject mockForClass:[SOAPMessage class]];
! [[[msgMock expect] andReturn:RawSOAPMessage] XMLString];

! id channelMock = [OCMockObject mockForClass:[SOAPChannel class]];
! [[[channelMock expect] andReturn:TRUE] send];

! SOAPClient *client = [SOAPClient initWith:channelMock];
!
! [client sendMessage:msgMock];

! [msgMock verify];
! [channelMock verify];
}
Verify

static const NSString * RawSOAPMessage = @"<ENV:evn
xmlns:ENV="http://www.w3.org/....

- (void)testClientShouldSendMessage{
! id msgMock = [OCMockObject mockForClass:[SOAPMessage class]];
! [[[msgMock expect] andReturn:RawSOAPMessage] XMLString];

! id channelMock = [OCMockObject mockForClass:[SOAPChannel class]];
! [[[channelMock expect] andReturn:TRUE] send];

! SOAPClient *client = [SOAPClient initWith:channelMock];
!
! [client sendMessage:msgMock];

! [msgMock verify];
! [channelMock verify];
}
What’s wrong with Unit Testing?
TEST
Tdd isn’t about tests, but about
 behaviors and specifications
A spoonful of syntactic sugar...
A spoonful of syntactic sugar...




       Behavior Driven
       Development
should insted of test
matchers instead of Assert
Bdd framework for iPhone Dev...
Bdd framework for iPhone Dev...
Spec Example
-(void)before {
! [SpecHelper loginAsAdmin];
}

-(void)itShouldAddAUser {
! [app.navigationButton touch];
! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"];
! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"];
! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"];
! [[app.textField placeholder:@"Username"] setText:@"bkuser"];
! [[app.textField placeholder:@"Password"] setText:@"test"];
! [[app.textField placeholder:@"Confirm"] setText:@"test"];
! [[app.navigationButton.label text:@"Save"] touch];

! [app timeout:1].alertView.should.not.exist;
! [[app.tableView.label text:@"Brian Knorr"] should].exist;
}

-(void)after {
! [SpecHelper logout];
}
Fixture Setup
-(void)before {
! [SpecHelper loginAsAdmin];
}

-(void)itShouldAddAUser {
! [app.navigationButton touch];
! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"];
! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"];
! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"];
! [[app.textField placeholder:@"Username"] setText:@"bkuser"];
! [[app.textField placeholder:@"Password"] setText:@"test"];
! [[app.textField placeholder:@"Confirm"] setText:@"test"];
! [[app.navigationButton.label text:@"Save"] touch];

! [app timeout:1].alertView.should.not.exist;
! [[app.tableView.label text:@"Brian Knorr"] should].exist;
}

-(void)after {
! [SpecHelper logout];
}
Exercise SUT
-(void)before {
! [SpecHelper loginAsAdmin];
}

-(void)itShouldAddAUser {
! [app.navigationButton touch];
! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"];
! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"];
! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"];
! [[app.textField placeholder:@"Username"] setText:@"bkuser"];
! [[app.textField placeholder:@"Password"] setText:@"test"];
! [[app.textField placeholder:@"Confirm"] setText:@"test"];
! [[app.navigationButton.label text:@"Save"] touch];

! [app timeout:1].alertView.should.not.exist;
! [[app.tableView.label text:@"Brian Knorr"] should].exist;
}

-(void)after {
! [SpecHelper logout];
}
Verify Result
-(void)before {
! [SpecHelper loginAsAdmin];
}

-(void)itShouldAddAUser {
! [app.navigationButton touch];
! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"];
! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"];
! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"];
! [[app.textField placeholder:@"Username"] setText:@"bkuser"];
! [[app.textField placeholder:@"Password"] setText:@"test"];
! [[app.textField placeholder:@"Confirm"] setText:@"test"];
! [[app.navigationButton.label text:@"Save"] touch];

! [app timeout:1].alertView.should.not.exist;
! [[app.tableView.label text:@"Brian Knorr"] should].exist;
}

-(void)after {
! [SpecHelper logout];
}
Fixture Teardown
-(void)before {
! [SpecHelper loginAsAdmin];
}

-(void)itShouldAddAUser {
! [app.navigationButton touch];
! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"];
! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"];
! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"];
! [[app.textField placeholder:@"Username"] setText:@"bkuser"];
! [[app.textField placeholder:@"Password"] setText:@"test"];
! [[app.textField placeholder:@"Confirm"] setText:@"test"];
! [[app.navigationButton.label text:@"Save"] touch];

! [app timeout:1].alertView.should.not.exist;
! [[app.tableView.label text:@"Brian Knorr"] should].exist;
}

-(void)after {
! [SpecHelper logout];
}
Run On Simulator
No XCode Integration Yet
Conclusions
The Market Asks For Apps
More Apps...
More Apps...
More Apps!
Lot to Improve
Be Good Kids:
Test First!
Reclame




http://milano-xpug.pbworks.com/
http://tech.groups.yahoo.com/group/milano-xpug/
Questions?

More Related Content

What's hot

Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
Una Critica a Rails by Luca Guidi
Una Critica a Rails by Luca GuidiUna Critica a Rails by Luca Guidi
Una Critica a Rails by Luca GuidiCodemotion
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jscacois
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDISven Ruppert
 
Laporan tugas network programming
Laporan tugas network programmingLaporan tugas network programming
Laporan tugas network programmingRahmatHamdani2
 
Unit Testing Express Middleware
Unit Testing Express MiddlewareUnit Testing Express Middleware
Unit Testing Express MiddlewareMorris Singer
 
Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017Colin Oakley
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.jsRotem Tamir
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Libraryasync_io
 
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionCool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionSchalk Cronjé
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node jsThomas Roch
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with JestMichał Pierzchała
 
Java Libraries You Can't Afford to Miss
Java Libraries You Can't Afford to MissJava Libraries You Can't Afford to Miss
Java Libraries You Can't Afford to MissAndres Almiray
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Andres Almiray
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptŁukasz Kużyński
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaKasun Indrasiri
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Andres Almiray
 

What's hot (20)

Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
Una Critica a Rails by Luca Guidi
Una Critica a Rails by Luca GuidiUna Critica a Rails by Luca Guidi
Una Critica a Rails by Luca Guidi
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDI
 
Laporan tugas network programming
Laporan tugas network programmingLaporan tugas network programming
Laporan tugas network programming
 
Unit Testing Express Middleware
Unit Testing Express MiddlewareUnit Testing Express Middleware
Unit Testing Express Middleware
 
Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
 
Angular testing
Angular testingAngular testing
Angular testing
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
 
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers VersionCool Jvm Tools to Help you Test - Aylesbury Testers Version
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with Jest
 
Java Libraries You Can't Afford to Miss
Java Libraries You Can't Afford to MissJava Libraries You Can't Afford to Miss
Java Libraries You Can't Afford to Miss
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
 

Viewers also liked

Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good codeGiordano Scalzo
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperGiordano Scalzo
 
PC for senior citizens
PC for senior citizens PC for senior citizens
PC for senior citizens Jo Va
 
iPhone and iPad Tips and Tricks
iPhone and iPad Tips and TricksiPhone and iPad Tips and Tricks
iPhone and iPad Tips and Tricksnexxtep
 
Password Management Tips
Password Management TipsPassword Management Tips
Password Management Tipsnexxtep
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartGabriele Lana
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival GuideGiordano Scalzo
 
JavaScript Coding Guidelines
JavaScript Coding GuidelinesJavaScript Coding Guidelines
JavaScript Coding GuidelinesOleksii Prohonnyi
 

Viewers also liked (10)

JavaScript Patterns
JavaScript PatternsJavaScript Patterns
JavaScript Patterns
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
 
Tame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapperTame Accidental Complexity with Ruby and MongoMapper
Tame Accidental Complexity with Ruby and MongoMapper
 
PC for senior citizens
PC for senior citizens PC for senior citizens
PC for senior citizens
 
iPhone and iPad Tips and Tricks
iPhone and iPad Tips and TricksiPhone and iPad Tips and Tricks
iPhone and iPad Tips and Tricks
 
Password Management Tips
Password Management TipsPassword Management Tips
Password Management Tips
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
JavaScript Coding Guidelines
JavaScript Coding GuidelinesJavaScript Coding Guidelines
JavaScript Coding Guidelines
 
Scrum in an hour
Scrum in an hourScrum in an hour
Scrum in an hour
 

Similar to Tdd iPhone For Dummies

Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best PracticesJitendra Zaa
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockRobot Media
 
Unit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaUnit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaRobot Media
 
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Julian Robichaux
 
DEV-1550: Why Java 8? Or, What's a Lambda? – IBM Connect 2017
DEV-1550: Why Java 8? Or, What's a Lambda? – IBM Connect 2017DEV-1550: Why Java 8? Or, What's a Lambda? – IBM Connect 2017
DEV-1550: Why Java 8? Or, What's a Lambda? – IBM Connect 2017panagenda
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everythingnoelrap
 
Anton Moldovan "Load testing which you always wanted"
Anton Moldovan "Load testing which you always wanted"Anton Moldovan "Load testing which you always wanted"
Anton Moldovan "Load testing which you always wanted"Fwdays
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special CasesCiklum Ukraine
 
SystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxSystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxNothing!
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It'sJim Lynch
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciollaAndrea Paciolla
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav DukhinFwdays
 
Testing in android
Testing in androidTesting in android
Testing in androidjtrindade
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based TestingC4Media
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanizecoreygoldberg
 

Similar to Tdd iPhone For Dummies (20)

iOS testing
iOS testingiOS testing
iOS testing
 
2013-01-10 iOS testing
2013-01-10 iOS testing2013-01-10 iOS testing
2013-01-10 iOS testing
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best Practices
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 
Unit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon GaliciaUnit testing en iOS @ MobileCon Galicia
Unit testing en iOS @ MobileCon Galicia
 
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
 
DEV-1550: Why Java 8? Or, What's a Lambda? – IBM Connect 2017
DEV-1550: Why Java 8? Or, What's a Lambda? – IBM Connect 2017DEV-1550: Why Java 8? Or, What's a Lambda? – IBM Connect 2017
DEV-1550: Why Java 8? Or, What's a Lambda? – IBM Connect 2017
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
Anton Moldovan "Load testing which you always wanted"
Anton Moldovan "Load testing which you always wanted"Anton Moldovan "Load testing which you always wanted"
Anton Moldovan "Load testing which you always wanted"
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special Cases
 
SystemVerilog Assertion.pptx
SystemVerilog Assertion.pptxSystemVerilog Assertion.pptx
SystemVerilog Assertion.pptx
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
 
Testing in android
Testing in androidTesting in android
Testing in android
 
An Introduction to Property Based Testing
An Introduction to Property Based TestingAn Introduction to Property Based Testing
An Introduction to Property Based Testing
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
 

More from Giordano Scalzo

The Joy Of Server Side Swift Development
The Joy Of Server Side Swift DevelopmentThe Joy Of Server Side Swift Development
The Joy Of Server Side Swift DevelopmentGiordano Scalzo
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftGiordano Scalzo
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano Scalzo
 
Better Software Developers
Better Software DevelopersBetter Software Developers
Better Software DevelopersGiordano Scalzo
 
Agile Iphone Development
Agile Iphone DevelopmentAgile Iphone Development
Agile Iphone DevelopmentGiordano Scalzo
 
XpUg Coding Dojo: KataYahtzee in Ocp way
XpUg Coding Dojo: KataYahtzee in Ocp wayXpUg Coding Dojo: KataYahtzee in Ocp way
XpUg Coding Dojo: KataYahtzee in Ocp wayGiordano Scalzo
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteGiordano Scalzo
 
10 minutes of me: Giordano Scalzo's Visual Resume
10 minutes of me: Giordano Scalzo's Visual Resume10 minutes of me: Giordano Scalzo's Visual Resume
10 minutes of me: Giordano Scalzo's Visual ResumeGiordano Scalzo
 

More from Giordano Scalzo (9)

The Joy Of Server Side Swift Development
The Joy Of Server Side Swift DevelopmentThe Joy Of Server Side Swift Development
The Joy Of Server Side Swift Development
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Code kata
Code kataCode kata
Code kata
 
Better Software Developers
Better Software DevelopersBetter Software Developers
Better Software Developers
 
Agile Iphone Development
Agile Iphone DevelopmentAgile Iphone Development
Agile Iphone Development
 
XpUg Coding Dojo: KataYahtzee in Ocp way
XpUg Coding Dojo: KataYahtzee in Ocp wayXpUg Coding Dojo: KataYahtzee in Ocp way
XpUg Coding Dojo: KataYahtzee in Ocp way
 
Bdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infiniteBdd: Tdd and beyond the infinite
Bdd: Tdd and beyond the infinite
 
10 minutes of me: Giordano Scalzo's Visual Resume
10 minutes of me: Giordano Scalzo's Visual Resume10 minutes of me: Giordano Scalzo's Visual Resume
10 minutes of me: Giordano Scalzo's Visual Resume
 

Recently uploaded

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Tdd iPhone For Dummies

  • 1.
  • 3.
  • 4. I’m not here to convince you
  • 5. Dry and easy to maintain
  • 6. Better form of documentation
  • 9. Tdd? Test-driven development (TDD) is a software development technique that relies on the repetition of a very short development cycle http://en.wikipedia.org/wiki/Test-driven_development
  • 10. Tdd? first the developer writes a failing automated test case that defines a desired improvement or new function http://en.wikipedia.org/wiki/Test-driven_development
  • 11. Tdd? then produces code to pass that test http://en.wikipedia.org/wiki/Test-driven_development
  • 12. Tdd? and finally refactors the new code to acceptable standard http://en.wikipedia.org/wiki/Test-driven_development
  • 13. Unit Tests? A test is not a unit test if: Michael Feathers
  • 14. Unit Tests? It talks to a database Michael Feathers
  • 15. Unit Tests? It communicates across the network Michael Feathers
  • 16. Unit Tests? It touches the file system Michael Feathers
  • 17. Unit Tests? You have to do things to your environment to run it (eg, change config files) Michael Feathers
  • 18. Unit Tests? Tests that do this are integration tests Michael Feathers
  • 19. Automatic Testing Lifecycle Steps Fixture Setup
  • 20. Automatic Testing Lifecycle Steps Fixture Setup SUT Exercise SUT
  • 21. Automatic Testing Lifecycle Steps Fixture Setup SUT Exercise SUT Verify Result
  • 22. Automatic Testing Lifecycle Steps Fixture Setup Exercise SUT Verify Result Fixture TearDown
  • 26. TestCase definition #import <SenTestingKit/SenTestingKit.h> #import "RpnCalculator.h" @interface RpnCalculatorTestCase : SenTestCase { ! RpnCalculator* rpnCalculator; } @end
  • 27. TestCase definition #import <SenTestingKit/SenTestingKit.h> #import "RpnCalculator.h" @interface RpnCalculatorTestCase : SenTestCase { ! RpnCalculator* rpnCalculator; } @end
  • 28. TestCase Implementation @implementation RpnCalculatorTestCase -(void)setUp{ ! rpnCalculator = [[RpnCalculator alloc]init]; } -(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{ ! [rpnCalculator put:@"1"]; ! [rpnCalculator put:@"enter"]; ! [rpnCalculator put:@"2"];! ! ! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil); } -(void)tearDown{ [rpnCalculator release]; }
  • 29. Fixture Setup @implementation RpnCalculatorTestCase -(void)setUp{ ! rpnCalculator = [[RpnCalculator alloc]init]; } -(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{ ! [rpnCalculator put:@"1"]; ! [rpnCalculator put:@"enter"]; ! [rpnCalculator put:@"2"];! ! ! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil); } -(void)tearDown{ [rpnCalculator release]; }
  • 30. Exercise SUT @implementation RpnCalculatorTestCase -(void)setUp{ ! rpnCalculator = [[RpnCalculator alloc]init]; } -(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{ ! [rpnCalculator put:@"1"]; ! [rpnCalculator put:@"enter"]; ! [rpnCalculator put:@"2"];! ! ! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil); } -(void)tearDown{ [rpnCalculator release]; }
  • 31. Verify Result @implementation RpnCalculatorTestCase -(void)setUp{ ! rpnCalculator = [[RpnCalculator alloc]init]; } -(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{ ! [rpnCalculator put:@"1"]; ! [rpnCalculator put:@"enter"]; ! [rpnCalculator put:@"2"];! ! ! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil); } -(void)tearDown{ [rpnCalculator release]; }
  • 32. Fixture Teardown @implementation RpnCalculatorTestCase -(void)setUp{ ! rpnCalculator = [[RpnCalculator alloc]init]; } -(void)testShouldDisplayTwoNumbersWhenNumbersAreSeparatedByEnter{ ! [rpnCalculator put:@"1"]; ! [rpnCalculator put:@"enter"]; ! [rpnCalculator put:@"2"];! ! ! STAssertEqualObjects(@"1n2",rpnCalculator.display,nil); } -(void)tearDown{ [rpnCalculator release]; }
  • 33. Assertions #define STAssertNil(a1, description, ...) #define STAssertNotNil(a1, description, ...) #define STAssertTrue(expression, description, ...) #define STAssertFalse(expression, description, ...) #define STAssertEqualObjects(a1, a2, description, ...) #define STAssertEquals(a1, a2, description, ...) #define STFail(description, ...) #define STAssertTrueNoThrow(expression, description, ...) #define STAssertFalseNoThrow(expression, description, ...) //....
  • 39. Logic
  • 40. Test
  • 43. What if I have to access network...
  • 44. Or I have correlated components..
  • 46. Mock it! [...] mock objects are simulated objects that mimic the behavior of real objects in controlled ways
  • 48. Stubs vs Mocks Mocks Stubs
  • 49. Stub - (void)testReturnsStubbedReturnValue { ! mock = [OCMockObject mockForClass:[NSString class]]; [[[mock stub] andReturn:@"megamock"] lowercaseString]; id returnValue = [mock lowercaseString]; ! STAssertEqualObjects(@"megamock", returnValue, nil); }
  • 50. Collaboration SOAPMessage XMLString SOAPClient send SOAPChannel post
  • 51. Collaboration SOAPMessage XMLString SOAPClient send SOAPChannel post
  • 52. Collaboration SOAPMessage XMLString SOAPClient send SOAPChannel post
  • 53. Mock static const NSString * RawSOAPMessage = @"<ENV:evn xmlns:ENV="http://www.w3.org/.... - (void)testClientShouldSendMessage{ ! id msgMock = [OCMockObject mockForClass:[SOAPMessage class]]; ! [[[msgMock expect] andReturn:RawSOAPMessage] XMLString]; ! id channelMock = [OCMockObject mockForClass:[SOAPChannel class]]; ! [[[channelMock expect] andReturn:TRUE] send]; ! SOAPClient *client = [SOAPClient initWith:channelMock]; ! ! [client sendMessage:msgMock]; ! [msgMock verify]; ! [channelMock verify]; }
  • 54. Mockery static const NSString * RawSOAPMessage = @"<ENV:evn xmlns:ENV="http://www.w3.org/.... - (void)testClientShouldSendMessage{ ! id msgMock = [OCMockObject mockForClass:[SOAPMessage class]]; ! [[[msgMock expect] andReturn:RawSOAPMessage] XMLString]; ! id channelMock = [OCMockObject mockForClass:[SOAPChannel class]]; ! [[[channelMock expect] andReturn:TRUE] send]; ! SOAPClient *client = [SOAPClient initWith:channelMock]; ! ! [client sendMessage:msgMock]; ! [msgMock verify]; ! [channelMock verify]; }
  • 55. Exercise SUT static const NSString * RawSOAPMessage = @"<ENV:evn xmlns:ENV="http://www.w3.org/.... - (void)testClientShouldSendMessage{ ! id msgMock = [OCMockObject mockForClass:[SOAPMessage class]]; ! [[[msgMock expect] andReturn:RawSOAPMessage] XMLString]; ! id channelMock = [OCMockObject mockForClass:[SOAPChannel class]]; ! [[[channelMock expect] andReturn:TRUE] send]; ! SOAPClient *client = [SOAPClient initWith:channelMock]; ! ! [client sendMessage:msgMock]; ! [msgMock verify]; ! [channelMock verify]; }
  • 56. Verify static const NSString * RawSOAPMessage = @"<ENV:evn xmlns:ENV="http://www.w3.org/.... - (void)testClientShouldSendMessage{ ! id msgMock = [OCMockObject mockForClass:[SOAPMessage class]]; ! [[[msgMock expect] andReturn:RawSOAPMessage] XMLString]; ! id channelMock = [OCMockObject mockForClass:[SOAPChannel class]]; ! [[[channelMock expect] andReturn:TRUE] send]; ! SOAPClient *client = [SOAPClient initWith:channelMock]; ! ! [client sendMessage:msgMock]; ! [msgMock verify]; ! [channelMock verify]; }
  • 57. What’s wrong with Unit Testing?
  • 58. TEST
  • 59. Tdd isn’t about tests, but about behaviors and specifications
  • 60. A spoonful of syntactic sugar...
  • 61. A spoonful of syntactic sugar... Behavior Driven Development
  • 62. should insted of test matchers instead of Assert
  • 63. Bdd framework for iPhone Dev...
  • 64. Bdd framework for iPhone Dev...
  • 65. Spec Example -(void)before { ! [SpecHelper loginAsAdmin]; } -(void)itShouldAddAUser { ! [app.navigationButton touch]; ! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"]; ! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"]; ! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"]; ! [[app.textField placeholder:@"Username"] setText:@"bkuser"]; ! [[app.textField placeholder:@"Password"] setText:@"test"]; ! [[app.textField placeholder:@"Confirm"] setText:@"test"]; ! [[app.navigationButton.label text:@"Save"] touch]; ! [app timeout:1].alertView.should.not.exist; ! [[app.tableView.label text:@"Brian Knorr"] should].exist; } -(void)after { ! [SpecHelper logout]; }
  • 66. Fixture Setup -(void)before { ! [SpecHelper loginAsAdmin]; } -(void)itShouldAddAUser { ! [app.navigationButton touch]; ! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"]; ! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"]; ! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"]; ! [[app.textField placeholder:@"Username"] setText:@"bkuser"]; ! [[app.textField placeholder:@"Password"] setText:@"test"]; ! [[app.textField placeholder:@"Confirm"] setText:@"test"]; ! [[app.navigationButton.label text:@"Save"] touch]; ! [app timeout:1].alertView.should.not.exist; ! [[app.tableView.label text:@"Brian Knorr"] should].exist; } -(void)after { ! [SpecHelper logout]; }
  • 67. Exercise SUT -(void)before { ! [SpecHelper loginAsAdmin]; } -(void)itShouldAddAUser { ! [app.navigationButton touch]; ! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"]; ! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"]; ! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"]; ! [[app.textField placeholder:@"Username"] setText:@"bkuser"]; ! [[app.textField placeholder:@"Password"] setText:@"test"]; ! [[app.textField placeholder:@"Confirm"] setText:@"test"]; ! [[app.navigationButton.label text:@"Save"] touch]; ! [app timeout:1].alertView.should.not.exist; ! [[app.tableView.label text:@"Brian Knorr"] should].exist; } -(void)after { ! [SpecHelper logout]; }
  • 68. Verify Result -(void)before { ! [SpecHelper loginAsAdmin]; } -(void)itShouldAddAUser { ! [app.navigationButton touch]; ! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"]; ! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"]; ! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"]; ! [[app.textField placeholder:@"Username"] setText:@"bkuser"]; ! [[app.textField placeholder:@"Password"] setText:@"test"]; ! [[app.textField placeholder:@"Confirm"] setText:@"test"]; ! [[app.navigationButton.label text:@"Save"] touch]; ! [app timeout:1].alertView.should.not.exist; ! [[app.tableView.label text:@"Brian Knorr"] should].exist; } -(void)after { ! [SpecHelper logout]; }
  • 69. Fixture Teardown -(void)before { ! [SpecHelper loginAsAdmin]; } -(void)itShouldAddAUser { ! [app.navigationButton touch]; ! [[app.textField.with placeholder:@"First Name"] setText:@"Brian"]; ! [[app.textField.with placeholder:@"Last Name"] setText:@"Knorr"]; ! [[app.textField.with placeholder:@"Email"] setText:@"b@g.com"]; ! [[app.textField placeholder:@"Username"] setText:@"bkuser"]; ! [[app.textField placeholder:@"Password"] setText:@"test"]; ! [[app.textField placeholder:@"Confirm"] setText:@"test"]; ! [[app.navigationButton.label text:@"Save"] touch]; ! [app timeout:1].alertView.should.not.exist; ! [[app.tableView.label text:@"Brian Knorr"] should].exist; } -(void)after { ! [SpecHelper logout]; }
  • 73. The Market Asks For Apps
  • 80.