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

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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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 ...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

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.