SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Testing in iOS
10.01.2013 by Tomasz Janeczko
About me
Tomasz Janeczko
• iOS developer in Kainos
• Enthusiast of business, electronics, Rails
& Heroku
• Organizer of first App Camp in UK and
PL
So let’s talk about testing.
Why we test?
So?
• Reliability
• Regression
• Confidence (e.g. refactoring)
Why not to test?
Why not to test?
• Heavy dependence on UI
• Non-testable code
• Bad framework
How to address issues
• Sample - downloading stuff from
interwebz
First fault
Writing tests after
writing code
Separation of concerns
Separation of concerns
• Let’s separate out the UI code
• Same for services interaction
Demo of tests
Writing tests
Meet Kiwi and OCMock
Kiwi
• RSpec-like tests writing
• Matchers
• Cleaner and more self-descriptive code
Kiwi
describe(@"Tested class", ^{
context(@"When created", ^{
it(@"should not fail", ^{
[[theValue(0) should] equal:theValue(0)];
});
});
});
Kiwi
describe(@"Tested class", ^{
context(@"When created", ^{
it(@"should not fail", ^{
id viewController = [ViewController new];
[[viewController should]
conformToProtocol:@protocol(UITableViewDelegate)];
});
});
});
Matchers
[subject	
  shouldNotBeNil]
• [subject	
  shouldBeNil]
• [[subject	
  should]	
  beIdenticalTo:(id)anObject] - compares id's
• [[subject	
  should]	
  equal:(id)anObject]
• [[subject	
  should]	
  equal:(double)aValue	
  withDelta:
(double)aDelta]
• [[subject	
  should]	
  beWithin:(id)aDistance	
  of:(id)aValue]
• [[subject	
  should]	
  beLessThan:(id)aValue]
• etc.	
  etc.
Compare to SenTesting Kit
[[subject	
  should]	
  equal:anObject]
compare	
  with
STAssertEquals(subject,	
  anObject,	
  @”Should	
  be	
  equal”);
OCMock
• Mocking and stubbing library for iOS
• Quite versatile
• Makes use of NSProxy magic
Sample workflows
Classic calculator sample
describe(@"Calculator",	
  ^{	
  	
  	
  	
  
	
  	
  	
  	
  context(@"with	
  the	
  numbers	
  60	
  and	
  5	
  entered",	
  ^{
	
  	
  	
  	
  	
  	
  	
  	
  RPNCalculator	
  *calculator	
  =	
  [[RPNCalculator	
  alloc]	
  init];	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  beforeEach(^{
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  [calculator	
  enter:60];
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  [calculator	
  enter:5];
	
  	
  	
  	
  	
  	
  	
  	
  });
	
  	
  	
  	
  	
  	
  	
  	
  afterEach(^{	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  [calculator	
  clear];
	
  	
  	
  	
  	
  	
  	
  	
  });
	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  it(@"returns	
  65	
  as	
  the	
  sum",	
  ^{
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  [[theValue([calculator	
  add])	
  should]	
  equal:65	
  withDelta:.01];
	
  	
  	
  	
  	
  	
  	
  	
  });
Test if calls dep methods
1. Create a mock dependency
2. Inject it
3. Call the method
4. Verify
Test dependency
// Create the tested object and mock to exchange part of the functionality
viewController = [ViewController new];
mockController = [OCMockObject partialMockForObject:viewController];
// Create the mock and change implementation to return our class
id serviceMock = [OCMockObject mockForClass:[InterwebzService class]];
[[[mockController stub] andReturn:serviceMock] service];
// Define expectations
[[serviceMock expect] downloadTweetsJSONWithSuccessBlock:[OCMArg any]];
// Run the tested method
[viewController tweetsButtonTapped:nil];
// Verify - throws exception on failure
[mockController verify];
Testing one layer
• Isolate dependencies
• Objective-C is highly dynamic - we can
change implementations of private
methods or static methods
• We can avoid IoC containers for testing
Accessing private methods
Accessing private methods
@interface ViewController()
- (void)startDownloadingTweets;
@end
...
[[mockController expect] startDownloadingTweets];
Static method testing
• Through separation to a method
@interface ViewController()
- (NSUserDefaults *)userDefaults;
@end
...
id mockDefaults = [OCMockObject mockForClass:[NSUserDefaults class]];
[[[mockDefaults expect] andReturn:@"Setting"] valueForKey:[OCMArg any]];
[[[mockController stub] andReturn:mockDefaults] userDefaults];
Static method testing
• Through method swizzling
void	
  SwizzleClassMethod(Class	
  c,	
  SEL	
  orig,	
  SEL	
  new)	
  {
	
  	
  	
  	
  Method	
  origMethod	
  =	
  class_getClassMethod(c,	
  orig);
	
  	
  	
  	
  Method	
  newMethod	
  =	
  class_getClassMethod(c,	
  new);
	
  	
  	
  	
  c	
  =	
  object_getClass((id)c);
	
  	
  	
  	
  if(class_addMethod(c,	
  orig,	
  method_getImplementation(newMethod),	
  method_getTypeEncoding(newMethod)))
	
  	
  	
  	
  	
  	
  	
  	
  class_replaceMethod(c,	
  new,	
  method_getImplementation(origMethod),	
  
method_getTypeEncoding(origMethod));
	
  	
  	
  	
  else
	
  	
  	
  	
  	
  	
  	
  	
  method_exchangeImplementations(origMethod,	
  newMethod);
}
Normal conditions apply
despite it’s iOS & Objective--C
Problems of „mobile devs”
• Pushing code with failing tests
• Lot’s of hacking together
• Weak knowledge of VCS tools - merge
nightmares
Ending thoughts
• Think first (twice), then code :)
• Tests should come first
• Write the failing test, pass the test,
refactor
• Adequate tools can enhance your
testing experience
Ending thoughts
• Practice!
Thanks!
Questions

Weitere ähnliche Inhalte

Was ist angesagt?

An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2 Apptension
 
React js t8 - inlinecss
React js   t8 - inlinecssReact js   t8 - inlinecss
React js t8 - inlinecssJainul Musani
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2Ivan Matiishyn
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developersYakov Fain
 
Selenium Training in Chennai Demo Part-2
Selenium Training in Chennai Demo Part-2 Selenium Training in Chennai Demo Part-2
Selenium Training in Chennai Demo Part-2 Thecreating Experts
 
Soap ui introduction
Soap ui introductionSoap ui introduction
Soap ui introductionIkuru Kanuma
 
Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Ahmed Moawad
 
Modern Web Developement
Modern Web DevelopementModern Web Developement
Modern Web Developementpeychevi
 
Infinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactiveInfinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactiveInfinum
 
Angular Unit Testing from the Trenches
Angular Unit Testing from the TrenchesAngular Unit Testing from the Trenches
Angular Unit Testing from the TrenchesJustin James
 
Redux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncRedux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncArtur Szott
 

Was ist angesagt? (19)

Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Ngrx meta reducers
Ngrx meta reducersNgrx meta reducers
Ngrx meta reducers
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2
 
D3_Tuto_GD
D3_Tuto_GDD3_Tuto_GD
D3_Tuto_GD
 
React js t8 - inlinecss
React js   t8 - inlinecssReact js   t8 - inlinecss
React js t8 - inlinecss
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
Angular genericforms2
Angular genericforms2Angular genericforms2
Angular genericforms2
 
Unit testing on mobile apps
Unit testing on mobile appsUnit testing on mobile apps
Unit testing on mobile apps
 
Selenium Training in Chennai Demo Part-2
Selenium Training in Chennai Demo Part-2 Selenium Training in Chennai Demo Part-2
Selenium Training in Chennai Demo Part-2
 
Angular 5
Angular 5Angular 5
Angular 5
 
Soap ui introduction
Soap ui introductionSoap ui introduction
Soap ui introduction
 
Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2
 
Active x
Active xActive x
Active x
 
Modern Web Developement
Modern Web DevelopementModern Web Developement
Modern Web Developement
 
Infinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactiveInfinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactive
 
Angular Unit Testing from the Trenches
Angular Unit Testing from the TrenchesAngular Unit Testing from the Trenches
Angular Unit Testing from the Trenches
 
Redux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncRedux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with Async
 

Andere mochten auch

Pemerintah kota makassar
Pemerintah kota makassarPemerintah kota makassar
Pemerintah kota makassarsmpn05makassar
 
Reise in deutschland
Reise in deutschlandReise in deutschland
Reise in deutschlandInna180993
 
CIC IWOM Panel: Jiepang CEO David on The New Age of Social Networking
CIC IWOM Panel: Jiepang CEO David on The New Age of Social NetworkingCIC IWOM Panel: Jiepang CEO David on The New Age of Social Networking
CIC IWOM Panel: Jiepang CEO David on The New Age of Social NetworkingKantar Media CIC
 
freddy quispe condori deporte adaptado
freddy quispe condori deporte adaptadofreddy quispe condori deporte adaptado
freddy quispe condori deporte adaptadoFreddy Quispe
 
Code breaker vol 03 cap 16
Code breaker vol 03 cap 16Code breaker vol 03 cap 16
Code breaker vol 03 cap 16Jonatan Garcia
 

Andere mochten auch (9)

Pemerintah kota makassar
Pemerintah kota makassarPemerintah kota makassar
Pemerintah kota makassar
 
Reise in deutschland
Reise in deutschlandReise in deutschland
Reise in deutschland
 
Chancado
ChancadoChancado
Chancado
 
Naruto vol 02 cap 12
Naruto vol 02 cap 12Naruto vol 02 cap 12
Naruto vol 02 cap 12
 
Dating For Men
Dating For MenDating For Men
Dating For Men
 
Naruto vol 03 cap 26
Naruto vol 03 cap 26Naruto vol 03 cap 26
Naruto vol 03 cap 26
 
CIC IWOM Panel: Jiepang CEO David on The New Age of Social Networking
CIC IWOM Panel: Jiepang CEO David on The New Age of Social NetworkingCIC IWOM Panel: Jiepang CEO David on The New Age of Social Networking
CIC IWOM Panel: Jiepang CEO David on The New Age of Social Networking
 
freddy quispe condori deporte adaptado
freddy quispe condori deporte adaptadofreddy quispe condori deporte adaptado
freddy quispe condori deporte adaptado
 
Code breaker vol 03 cap 16
Code breaker vol 03 cap 16Code breaker vol 03 cap 16
Code breaker vol 03 cap 16
 

Ähnlich wie 2013-01-10 iOS testing

Building stable testing by isolating network layer
Building stable testing by isolating network layerBuilding stable testing by isolating network layer
Building stable testing by isolating network layerJz Chang
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testabilitydrewz lin
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsSubhransu Behera
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing MicroservicesAnil Allewar
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeMark Meyer
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Roy de Kleijn
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It'sJim Lynch
 
It depends: Loving .NET Core dependency injection or not
It depends: Loving .NET Core dependency injection or notIt depends: Loving .NET Core dependency injection or not
It depends: Loving .NET Core dependency injection or notAlex Thissen
 
10 tips for a reusable architecture
10 tips for a reusable architecture10 tips for a reusable architecture
10 tips for a reusable architectureJorge Ortiz
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptxStefan Oprea
 
Spring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUGSpring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUGTed Pennings
 
High ROI Testing in Angular.pptx
High ROI Testing in Angular.pptxHigh ROI Testing in Angular.pptx
High ROI Testing in Angular.pptxChristian Lüdemann
 
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaDsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaUgo Matrangolo
 
Legacy Dependency Killer - Utah Code Camp 2014
Legacy Dependency Killer - Utah Code Camp 2014Legacy Dependency Killer - Utah Code Camp 2014
Legacy Dependency Killer - Utah Code Camp 2014dubmun
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014FalafelSoftware
 

Ähnlich wie 2013-01-10 iOS testing (20)

Building stable testing by isolating network layer
Building stable testing by isolating network layerBuilding stable testing by isolating network layer
Building stable testing by isolating network layer
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For Dummies
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
 
mean stack
mean stackmean stack
mean stack
 
Frontend training
Frontend trainingFrontend training
Frontend training
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing Microservices
 
From mvc to viper
From mvc to viperFrom mvc to viper
From mvc to viper
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers Make
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOS
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
 
It depends: Loving .NET Core dependency injection or not
It depends: Loving .NET Core dependency injection or notIt depends: Loving .NET Core dependency injection or not
It depends: Loving .NET Core dependency injection or not
 
10 tips for a reusable architecture
10 tips for a reusable architecture10 tips for a reusable architecture
10 tips for a reusable architecture
 
Web technologies-course 12.pptx
Web technologies-course 12.pptxWeb technologies-course 12.pptx
Web technologies-course 12.pptx
 
Spring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUGSpring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUG
 
High ROI Testing in Angular.pptx
High ROI Testing in Angular.pptxHigh ROI Testing in Angular.pptx
High ROI Testing in Angular.pptx
 
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in ScalaDsug 05 02-15 - ScalDI - lightweight DI in Scala
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
 
Legacy Dependency Killer - Utah Code Camp 2014
Legacy Dependency Killer - Utah Code Camp 2014Legacy Dependency Killer - Utah Code Camp 2014
Legacy Dependency Killer - Utah Code Camp 2014
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 

Mehr von CocoaHeads Tricity

[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...
[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...
[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...CocoaHeads Tricity
 
[CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps
[CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps[CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps
[CocoaHeads Tricity] Michał Tuszyński - Modern iOS AppsCocoaHeads Tricity
 
[CocoaHeads Tricity] Michał Zygar - Consuming API
[CocoaHeads Tricity] Michał Zygar - Consuming API[CocoaHeads Tricity] Michał Zygar - Consuming API
[CocoaHeads Tricity] Michał Zygar - Consuming APICocoaHeads Tricity
 
[CocoaHeads Tricity] Maciej Burda - Working as an iOS developer Interview Cas...
[CocoaHeads Tricity] Maciej Burda - Working as an iOS developer Interview Cas...[CocoaHeads Tricity] Maciej Burda - Working as an iOS developer Interview Cas...
[CocoaHeads Tricity] Maciej Burda - Working as an iOS developer Interview Cas...CocoaHeads Tricity
 
2013-05-15 threads. why and how
2013-05-15 threads. why and how2013-05-15 threads. why and how
2013-05-15 threads. why and howCocoaHeads Tricity
 
2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkitCocoaHeads Tricity
 
2013-02-05 UX design for mobile apps
2013-02-05 UX design for mobile apps2013-02-05 UX design for mobile apps
2013-02-05 UX design for mobile appsCocoaHeads Tricity
 
2013-04-16 iOS development speed up
2013-04-16 iOS development speed up2013-04-16 iOS development speed up
2013-04-16 iOS development speed upCocoaHeads Tricity
 

Mehr von CocoaHeads Tricity (8)

[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...
[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...
[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...
 
[CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps
[CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps[CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps
[CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps
 
[CocoaHeads Tricity] Michał Zygar - Consuming API
[CocoaHeads Tricity] Michał Zygar - Consuming API[CocoaHeads Tricity] Michał Zygar - Consuming API
[CocoaHeads Tricity] Michał Zygar - Consuming API
 
[CocoaHeads Tricity] Maciej Burda - Working as an iOS developer Interview Cas...
[CocoaHeads Tricity] Maciej Burda - Working as an iOS developer Interview Cas...[CocoaHeads Tricity] Maciej Burda - Working as an iOS developer Interview Cas...
[CocoaHeads Tricity] Maciej Burda - Working as an iOS developer Interview Cas...
 
2013-05-15 threads. why and how
2013-05-15 threads. why and how2013-05-15 threads. why and how
2013-05-15 threads. why and how
 
2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit
 
2013-02-05 UX design for mobile apps
2013-02-05 UX design for mobile apps2013-02-05 UX design for mobile apps
2013-02-05 UX design for mobile apps
 
2013-04-16 iOS development speed up
2013-04-16 iOS development speed up2013-04-16 iOS development speed up
2013-04-16 iOS development speed up
 

Kürzlich hochgeladen

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

2013-01-10 iOS testing

  • 1. Testing in iOS 10.01.2013 by Tomasz Janeczko
  • 2. About me Tomasz Janeczko • iOS developer in Kainos • Enthusiast of business, electronics, Rails & Heroku • Organizer of first App Camp in UK and PL
  • 3. So let’s talk about testing.
  • 5.
  • 6. So?
  • 7. • Reliability • Regression • Confidence (e.g. refactoring)
  • 8. Why not to test?
  • 9. Why not to test? • Heavy dependence on UI • Non-testable code • Bad framework
  • 10. How to address issues • Sample - downloading stuff from interwebz
  • 11. First fault Writing tests after writing code
  • 13. Separation of concerns • Let’s separate out the UI code • Same for services interaction
  • 16. Kiwi • RSpec-like tests writing • Matchers • Cleaner and more self-descriptive code
  • 17. Kiwi describe(@"Tested class", ^{ context(@"When created", ^{ it(@"should not fail", ^{ [[theValue(0) should] equal:theValue(0)]; }); }); });
  • 18. Kiwi describe(@"Tested class", ^{ context(@"When created", ^{ it(@"should not fail", ^{ id viewController = [ViewController new]; [[viewController should] conformToProtocol:@protocol(UITableViewDelegate)]; }); }); });
  • 19. Matchers [subject  shouldNotBeNil] • [subject  shouldBeNil] • [[subject  should]  beIdenticalTo:(id)anObject] - compares id's • [[subject  should]  equal:(id)anObject] • [[subject  should]  equal:(double)aValue  withDelta: (double)aDelta] • [[subject  should]  beWithin:(id)aDistance  of:(id)aValue] • [[subject  should]  beLessThan:(id)aValue] • etc.  etc.
  • 20. Compare to SenTesting Kit [[subject  should]  equal:anObject] compare  with STAssertEquals(subject,  anObject,  @”Should  be  equal”);
  • 21. OCMock • Mocking and stubbing library for iOS • Quite versatile • Makes use of NSProxy magic
  • 23. Classic calculator sample describe(@"Calculator",  ^{                context(@"with  the  numbers  60  and  5  entered",  ^{                RPNCalculator  *calculator  =  [[RPNCalculator  alloc]  init];                                beforeEach(^{                        [calculator  enter:60];                        [calculator  enter:5];                });                afterEach(^{                          [calculator  clear];                });                              it(@"returns  65  as  the  sum",  ^{                        [[theValue([calculator  add])  should]  equal:65  withDelta:.01];                });
  • 24. Test if calls dep methods 1. Create a mock dependency 2. Inject it 3. Call the method 4. Verify
  • 25. Test dependency // Create the tested object and mock to exchange part of the functionality viewController = [ViewController new]; mockController = [OCMockObject partialMockForObject:viewController]; // Create the mock and change implementation to return our class id serviceMock = [OCMockObject mockForClass:[InterwebzService class]]; [[[mockController stub] andReturn:serviceMock] service]; // Define expectations [[serviceMock expect] downloadTweetsJSONWithSuccessBlock:[OCMArg any]]; // Run the tested method [viewController tweetsButtonTapped:nil]; // Verify - throws exception on failure [mockController verify];
  • 26. Testing one layer • Isolate dependencies • Objective-C is highly dynamic - we can change implementations of private methods or static methods • We can avoid IoC containers for testing
  • 28. Accessing private methods @interface ViewController() - (void)startDownloadingTweets; @end ... [[mockController expect] startDownloadingTweets];
  • 29. Static method testing • Through separation to a method @interface ViewController() - (NSUserDefaults *)userDefaults; @end ... id mockDefaults = [OCMockObject mockForClass:[NSUserDefaults class]]; [[[mockDefaults expect] andReturn:@"Setting"] valueForKey:[OCMArg any]]; [[[mockController stub] andReturn:mockDefaults] userDefaults];
  • 30. Static method testing • Through method swizzling void  SwizzleClassMethod(Class  c,  SEL  orig,  SEL  new)  {        Method  origMethod  =  class_getClassMethod(c,  orig);        Method  newMethod  =  class_getClassMethod(c,  new);        c  =  object_getClass((id)c);        if(class_addMethod(c,  orig,  method_getImplementation(newMethod),  method_getTypeEncoding(newMethod)))                class_replaceMethod(c,  new,  method_getImplementation(origMethod),   method_getTypeEncoding(origMethod));        else                method_exchangeImplementations(origMethod,  newMethod); }
  • 31. Normal conditions apply despite it’s iOS & Objective--C
  • 32. Problems of „mobile devs” • Pushing code with failing tests • Lot’s of hacking together • Weak knowledge of VCS tools - merge nightmares
  • 33. Ending thoughts • Think first (twice), then code :) • Tests should come first • Write the failing test, pass the test, refactor • Adequate tools can enhance your testing experience