際際滷

際際滷Share a Scribd company logo
Testing and ViewControllers
"Extract testable code
&
Test UI without the simulator.
Small is the beauty!
 What did I do?
 Why / When / Dangers unit test
 A way to make viewControllers testable
 Make tests visible
What did I do
 TDD at Philips, small and big projects
 Lots of legacy code refactoring
 App that could have bene鍖tted from testing
Unit testing
Integration testing
Webservice
Local device test
External web
service
VCs Mock web service Views
UI Automation (Calabash)
Helped Developers
Helped ?
Legacy code
Legacy class
Sprout Class -> Unit tests
Unit test killers:
 Object should not set there own properties.
 Reach out to a database
 Many dependencies, no default working state on its own
Legacy code
Object should not set there own properties.
class ExampleVC: UIViewController {
let userDefaults = NSUserDefaults.standardUserDefaults()
}
class ExampleVC: UIViewController {
var userDefaults : NSUserDefaults?
override func viewDidLoad() {
super.viewDidLoad()
userDefaults = NSUserDefaults.standardUserDefaults()
}
}
Legacy code
Object should not set there own properties.
class ExampleVC: UIViewController {
lazy var userDefaults : NSUserDefaults = {
NSUserDefaults.standardUserDefaults()
}()
}
Cocoa heads testing and viewcontrollers
Why
Tests written for code coverage
are a waste of time
Write them to write better code or stop writing tests!
When
Data
Manipulation
Draw view
What value should I use for
this IndexPath?
I need a list but I have an
object with properties
ViewController
Different states
Do not test animations wait
for the result
Only visible for a very peculiar
state
What value should I use for
this IndexPath?
Data
Manipulation
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TableViewCell
cell.label.text = self.datasource.item(indexPath)
return cell
}
func testThenHasMessageAndDescription() {
let resultMessage = tableDatasource.item(NSIndexPath(forItem: 0, inSection: 0))
let resultDescription = tableDatasource.item(NSIndexPath(forItem: 1, inSection: 0))
XCTAssertEqual(resultMessage!, Message)
XCTAssertEqual(resultDescription!, Description)
}
Data
Manipulation
I need a list but I have an
object with properties
let fakeResponse = ["message" : "bla", "description" : "bla some more"]
self.mappedArray = [fakeResponse["message"]!, fakeResponse["description"]!]
func item(indexPath: NSIndexPath) -> (String?){
if indexPath.item < mappedArray?.count{
return mappedArray![indexPath.item]
}else{
return nil
}
}
Draw view
Different states
Do not test animations wait
for the result
Draw view
- (void)testThenShowInPlaceError
{
XCTestExpectation *exp = [self expectationWithDescription:@"Wait for error view"];
self.viewController.viewControllerDatasource.respondWithError = YES;
[self.viewController.viewControllerDatasource reloadDataWithDataCompletion:nil
failure:nil animationCompletion:^(BOOL success) {
FBSnapshotVerifyView(self.viewController.view, @"");
[exp fulfill];
}];
NSTimeInterval animationTime = kAsyncViewsAnimationDuration;
[self waitForExpectationsWithTimeout:animationTime + 2 handler:nil];
}
Only visible for a very peculiar
state
Draw view
- (void)testThenOfferCancel
{
id vc = OCMPartialMock([[UIStoryboard storyboardWithName:@"Main" bundle:nil]
instantiateViewControllerWithIdentifier:@"ViewController"]);
//We only use a stub here to have faster test cycles
OCMStub([vc async_timeOutDelay]).andReturn(@1);
XCTestExpectation *exp = [self expectationWithDescription:@"Wait for cancel"];
[self offerCancelOnViewController:vc
exp: exp
test:^(XCTestExpectation *exp) {
FBSnapshotVerifyView(((UIViewController *) vc).view, @"");
[vc stopMocking];
[exp fulfill];
}];
}
Danger
Dont fall in love with your tests
Make VCs Testable
Data
Manipulation
Draw view
ViewController
SharedAsyncDatasource UIViewController+Async
Cocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollers
Demo
https://github.com/doozMen/SharedAsyncViewController
Make Tests visible
Tests are just as important as application
code. Why not put them together?
Jon Reid
Inspiration
 http://qualitycoding.org/xcode-unit-testing/
 http://iosunittesting.com
 https://github.com/Inferis/IIAsyncViewController
 Working Effectively with Legacy Code 
Michael Feathers

More Related Content

What's hot (20)

CocoaHeads Moscow. 亰亳亰 舒仗仂于, VIPole. 束舒仗仂 于 CoreData 舒亞亠亞舒仆仄亳 ...
CocoaHeads Moscow. 亰亳亰 舒仗仂于, VIPole. 束舒仗仂 于 CoreData  舒亞亠亞舒仆仄亳 ...CocoaHeads Moscow. 亰亳亰 舒仗仂于, VIPole. 束舒仗仂 于 CoreData  舒亞亠亞舒仆仄亳 ...
CocoaHeads Moscow. 亰亳亰 舒仗仂于, VIPole. 束舒仗仂 于 CoreData 舒亞亠亞舒仆仄亳 ...
Mail.ru Group
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Divakar Gu
React & Redux
React & ReduxReact & Redux
React & Redux
Federico Bond
Tweaking the interactive grid
Tweaking the interactive gridTweaking the interactive grid
Tweaking the interactive grid
Roel Hartman
Developing New Widgets for your Views in Owl
Developing New Widgets for your Views in OwlDeveloping New Widgets for your Views in Owl
Developing New Widgets for your Views in Owl
Odoo
React redux
React reduxReact redux
React redux
Michel Perez
Universal adbdriverinstaller
Universal adbdriverinstallerUniversal adbdriverinstaller
Universal adbdriverinstaller
George Manrike
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
React&redux
React&reduxReact&redux
React&redux
Blank Chen
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd Motto
Future Insights
A Quick Introduction to YQL
A Quick Introduction to YQLA Quick Introduction to YQL
A Quick Introduction to YQL
Max Manders
Angular redux
Angular reduxAngular redux
Angular redux
Nir Kaufman
React with Redux
React with ReduxReact with Redux
React with Redux
Stanimir Todorov
X-Code UI testing architecture and tools
X-Code UI testing architecture and toolsX-Code UI testing architecture and tools
X-Code UI testing architecture and tools
Jianbin LIN
From zero to hero with the reactive extensions for java script
From zero to hero with the reactive extensions for java scriptFrom zero to hero with the reactive extensions for java script
From zero to hero with the reactive extensions for java script
Maurice De Beijer [MVP]
Angular js 2.0, ng poznan 20.11
Angular js 2.0, ng poznan 20.11Angular js 2.0, ng poznan 20.11
Angular js 2.0, ng poznan 20.11
Kamil Augustynowicz
Backbone.js
Backbone.jsBackbone.js
Backbone.js
Knoldus Inc.
油Mwa class custom_files
油Mwa class custom_files油Mwa class custom_files
油Mwa class custom_files
Senthilkumar Shanmugam
Swift Delhi: Practical POP
Swift Delhi: Practical POPSwift Delhi: Practical POP
Swift Delhi: Practical POP
Natasha Murashev
CocoaHeads Moscow. 亰亳亰 舒仗仂于, VIPole. 束舒仗仂 于 CoreData 舒亞亠亞舒仆仄亳 ...
CocoaHeads Moscow. 亰亳亰 舒仗仂于, VIPole. 束舒仗仂 于 CoreData  舒亞亠亞舒仆仄亳 ...CocoaHeads Moscow. 亰亳亰 舒仗仂于, VIPole. 束舒仗仂 于 CoreData  舒亞亠亞舒仆仄亳 ...
CocoaHeads Moscow. 亰亳亰 舒仗仂于, VIPole. 束舒仗仂 于 CoreData 舒亞亠亞舒仆仄亳 ...
Mail.ru Group
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Divakar Gu
Tweaking the interactive grid
Tweaking the interactive gridTweaking the interactive grid
Tweaking the interactive grid
Roel Hartman
Developing New Widgets for your Views in Owl
Developing New Widgets for your Views in OwlDeveloping New Widgets for your Views in Owl
Developing New Widgets for your Views in Owl
Odoo
Universal adbdriverinstaller
Universal adbdriverinstallerUniversal adbdriverinstaller
Universal adbdriverinstaller
George Manrike
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
React&redux
React&reduxReact&redux
React&redux
Blank Chen
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd Motto
Future Insights
A Quick Introduction to YQL
A Quick Introduction to YQLA Quick Introduction to YQL
A Quick Introduction to YQL
Max Manders
Angular redux
Angular reduxAngular redux
Angular redux
Nir Kaufman
X-Code UI testing architecture and tools
X-Code UI testing architecture and toolsX-Code UI testing architecture and tools
X-Code UI testing architecture and tools
Jianbin LIN
From zero to hero with the reactive extensions for java script
From zero to hero with the reactive extensions for java scriptFrom zero to hero with the reactive extensions for java script
From zero to hero with the reactive extensions for java script
Maurice De Beijer [MVP]
Angular js 2.0, ng poznan 20.11
Angular js 2.0, ng poznan 20.11Angular js 2.0, ng poznan 20.11
Angular js 2.0, ng poznan 20.11
Kamil Augustynowicz
Swift Delhi: Practical POP
Swift Delhi: Practical POPSwift Delhi: Practical POP
Swift Delhi: Practical POP
Natasha Murashev

Similar to Cocoa heads testing and viewcontrollers (20)

Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
goodfriday
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
Andy Butland
iOS Talks 6: Unit Testing
iOS Talks 6: Unit TestingiOS Talks 6: Unit Testing
iOS Talks 6: Unit Testing
Marin Benevi
Swift Tableview iOS App Development
Swift Tableview iOS App DevelopmentSwift Tableview iOS App Development
Swift Tableview iOS App Development
Ketan Raval
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
KatyShimizu
.NET Database Toolkit
.NET Database Toolkit.NET Database Toolkit
.NET Database Toolkit
wlscaudill
Core Data with Swift 3.0
Core Data with Swift 3.0Core Data with Swift 3.0
Core Data with Swift 3.0
Korhan Bircan
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
Daniel Ballinger
Build Widgets
Build WidgetsBuild Widgets
Build Widgets
scottw
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, Macoscope
Macoscope
Wcf data services
Wcf data servicesWcf data services
Wcf data services
Eyal Vardi
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
Abhishek Sur
Do iOS Presentation - Mobile app architectures
Do iOS Presentation - Mobile app architecturesDo iOS Presentation - Mobile app architectures
Do iOS Presentation - Mobile app architectures
David Bro転a
Sql lite android
Sql lite androidSql lite android
Sql lite android
Dushyant Nasit
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDB
Michal Bigos
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverCassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
DataStax Academy
Getting Started with Datatsax .Net Driver
Getting Started with Datatsax .Net DriverGetting Started with Datatsax .Net Driver
Getting Started with Datatsax .Net Driver
DataStax Academy
SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8
Ben Abdallah Helmi
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_zybotech
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
goodfriday
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
Andy Butland
iOS Talks 6: Unit Testing
iOS Talks 6: Unit TestingiOS Talks 6: Unit Testing
iOS Talks 6: Unit Testing
Marin Benevi
Swift Tableview iOS App Development
Swift Tableview iOS App DevelopmentSwift Tableview iOS App Development
Swift Tableview iOS App Development
Ketan Raval
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
KatyShimizu
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
KatyShimizu
.NET Database Toolkit
.NET Database Toolkit.NET Database Toolkit
.NET Database Toolkit
wlscaudill
Core Data with Swift 3.0
Core Data with Swift 3.0Core Data with Swift 3.0
Core Data with Swift 3.0
Korhan Bircan
Using the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service ClientsUsing the Tooling API to Generate Apex SOAP Web Service Clients
Using the Tooling API to Generate Apex SOAP Web Service Clients
Daniel Ballinger
Build Widgets
Build WidgetsBuild Widgets
Build Widgets
scottw
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, Macoscope
Macoscope
Wcf data services
Wcf data servicesWcf data services
Wcf data services
Eyal Vardi
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
Abhishek Sur
Do iOS Presentation - Mobile app architectures
Do iOS Presentation - Mobile app architecturesDo iOS Presentation - Mobile app architectures
Do iOS Presentation - Mobile app architectures
David Bro転a
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDB
Michal Bigos
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverCassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
DataStax Academy
Getting Started with Datatsax .Net Driver
Getting Started with Datatsax .Net DriverGetting Started with Datatsax .Net Driver
Getting Started with Datatsax .Net Driver
DataStax Academy
SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8SCWCD : Thread safe servlets : CHAP : 8
SCWCD : Thread safe servlets : CHAP : 8
Ben Abdallah Helmi
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_zybotech

Recently uploaded (20)

CNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECHCNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECH
C Sai Kiran
CNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECHCNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECH
C Sai Kiran
UHV UNIT-I INTRODUCTION TO VALUE EDUCATION .pptx
UHV UNIT-I INTRODUCTION TO VALUE EDUCATION  .pptxUHV UNIT-I INTRODUCTION TO VALUE EDUCATION  .pptx
UHV UNIT-I INTRODUCTION TO VALUE EDUCATION .pptx
ariomthermal2031
Intro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching schemeIntro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching scheme
Priyanka Dange
BUILD WITH AI for GDG on campus MVJCE.pptx
BUILD WITH AI for GDG on campus MVJCE.pptxBUILD WITH AI for GDG on campus MVJCE.pptx
BUILD WITH AI for GDG on campus MVJCE.pptx
greeshmadj0
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
Production Planning & Control and Inventory Management.pptx
Production Planning & Control and Inventory Management.pptxProduction Planning & Control and Inventory Management.pptx
Production Planning & Control and Inventory Management.pptx
VirajPasare
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
Scalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M NotificationsScalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M Notifications
Gustavo Araujo
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Priyanka Dange
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control
Mastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdfMastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdf
Brion Mario
LA2-64 -bit assemby language program to count number of positive and negative...
LA2-64 -bit assemby language program to count number of positive and negative...LA2-64 -bit assemby language program to count number of positive and negative...
LA2-64 -bit assemby language program to count number of positive and negative...
VidyaAshokNemade
Why the Engineering Model is Key to Successful Projects
Why the Engineering Model is Key to Successful ProjectsWhy the Engineering Model is Key to Successful Projects
Why the Engineering Model is Key to Successful Projects
Maadhu Creatives-Model Making Company
PLANT CELL REACTORS presenation PTC amity
PLANT CELL REACTORS presenation PTC amityPLANT CELL REACTORS presenation PTC amity
PLANT CELL REACTORS presenation PTC amity
UrjaMoon
02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf
ruioliveira1921
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptxUHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
ariomthermal2031
Industry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and BeyondIndustry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and Beyond
GtxDriver
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Ignacio J. J. Palma Carazo
Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
CNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECHCNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECH
C Sai Kiran
CNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECHCNC Technology Unit-5 for IV Year 24-25 MECH
CNC Technology Unit-5 for IV Year 24-25 MECH
C Sai Kiran
UHV UNIT-I INTRODUCTION TO VALUE EDUCATION .pptx
UHV UNIT-I INTRODUCTION TO VALUE EDUCATION  .pptxUHV UNIT-I INTRODUCTION TO VALUE EDUCATION  .pptx
UHV UNIT-I INTRODUCTION TO VALUE EDUCATION .pptx
ariomthermal2031
Intro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching schemeIntro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching scheme
Priyanka Dange
BUILD WITH AI for GDG on campus MVJCE.pptx
BUILD WITH AI for GDG on campus MVJCE.pptxBUILD WITH AI for GDG on campus MVJCE.pptx
BUILD WITH AI for GDG on campus MVJCE.pptx
greeshmadj0
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
Production Planning & Control and Inventory Management.pptx
Production Planning & Control and Inventory Management.pptxProduction Planning & Control and Inventory Management.pptx
Production Planning & Control and Inventory Management.pptx
VirajPasare
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
Scalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M NotificationsScalling Rails: The Journey to 200M Notifications
Scalling Rails: The Journey to 200M Notifications
Gustavo Araujo
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Priyanka Dange
Mastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdfMastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdf
Brion Mario
LA2-64 -bit assemby language program to count number of positive and negative...
LA2-64 -bit assemby language program to count number of positive and negative...LA2-64 -bit assemby language program to count number of positive and negative...
LA2-64 -bit assemby language program to count number of positive and negative...
VidyaAshokNemade
PLANT CELL REACTORS presenation PTC amity
PLANT CELL REACTORS presenation PTC amityPLANT CELL REACTORS presenation PTC amity
PLANT CELL REACTORS presenation PTC amity
UrjaMoon
02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf
ruioliveira1921
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptxUHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
UHV Unit - 4 HARMONY IN THE NATURE AND EXISTENCE.pptx
ariomthermal2031
Industry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and BeyondIndustry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and Beyond
GtxDriver
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Analysis of Daylighting in Interior Spaces using the Daylight Factor - A Manu...
Ignacio J. J. Palma Carazo
Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket

Cocoa heads testing and viewcontrollers

  • 1. Testing and ViewControllers "Extract testable code & Test UI without the simulator. Small is the beauty!
  • 2. What did I do? Why / When / Dangers unit test A way to make viewControllers testable Make tests visible
  • 3. What did I do TDD at Philips, small and big projects Lots of legacy code refactoring App that could have bene鍖tted from testing
  • 4. Unit testing Integration testing Webservice Local device test External web service VCs Mock web service Views UI Automation (Calabash) Helped Developers Helped ?
  • 5. Legacy code Legacy class Sprout Class -> Unit tests Unit test killers: Object should not set there own properties. Reach out to a database Many dependencies, no default working state on its own
  • 6. Legacy code Object should not set there own properties. class ExampleVC: UIViewController { let userDefaults = NSUserDefaults.standardUserDefaults() } class ExampleVC: UIViewController { var userDefaults : NSUserDefaults? override func viewDidLoad() { super.viewDidLoad() userDefaults = NSUserDefaults.standardUserDefaults() } }
  • 7. Legacy code Object should not set there own properties. class ExampleVC: UIViewController { lazy var userDefaults : NSUserDefaults = { NSUserDefaults.standardUserDefaults() }() }
  • 9. Why Tests written for code coverage are a waste of time Write them to write better code or stop writing tests!
  • 10. When Data Manipulation Draw view What value should I use for this IndexPath? I need a list but I have an object with properties ViewController Different states Do not test animations wait for the result Only visible for a very peculiar state
  • 11. What value should I use for this IndexPath? Data Manipulation override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TableViewCell cell.label.text = self.datasource.item(indexPath) return cell } func testThenHasMessageAndDescription() { let resultMessage = tableDatasource.item(NSIndexPath(forItem: 0, inSection: 0)) let resultDescription = tableDatasource.item(NSIndexPath(forItem: 1, inSection: 0)) XCTAssertEqual(resultMessage!, Message) XCTAssertEqual(resultDescription!, Description) }
  • 12. Data Manipulation I need a list but I have an object with properties let fakeResponse = ["message" : "bla", "description" : "bla some more"] self.mappedArray = [fakeResponse["message"]!, fakeResponse["description"]!] func item(indexPath: NSIndexPath) -> (String?){ if indexPath.item < mappedArray?.count{ return mappedArray![indexPath.item] }else{ return nil } }
  • 14. Do not test animations wait for the result Draw view - (void)testThenShowInPlaceError { XCTestExpectation *exp = [self expectationWithDescription:@"Wait for error view"]; self.viewController.viewControllerDatasource.respondWithError = YES; [self.viewController.viewControllerDatasource reloadDataWithDataCompletion:nil failure:nil animationCompletion:^(BOOL success) { FBSnapshotVerifyView(self.viewController.view, @""); [exp fulfill]; }]; NSTimeInterval animationTime = kAsyncViewsAnimationDuration; [self waitForExpectationsWithTimeout:animationTime + 2 handler:nil]; }
  • 15. Only visible for a very peculiar state Draw view - (void)testThenOfferCancel { id vc = OCMPartialMock([[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"]); //We only use a stub here to have faster test cycles OCMStub([vc async_timeOutDelay]).andReturn(@1); XCTestExpectation *exp = [self expectationWithDescription:@"Wait for cancel"]; [self offerCancelOnViewController:vc exp: exp test:^(XCTestExpectation *exp) { FBSnapshotVerifyView(((UIViewController *) vc).view, @""); [vc stopMocking]; [exp fulfill]; }]; }
  • 16. Danger Dont fall in love with your tests
  • 17. Make VCs Testable Data Manipulation Draw view ViewController SharedAsyncDatasource UIViewController+Async
  • 22. Make Tests visible Tests are just as important as application code. Why not put them together? Jon Reid
  • 23. Inspiration http://qualitycoding.org/xcode-unit-testing/ http://iosunittesting.com https://github.com/Inferis/IIAsyncViewController Working Effectively with Legacy Code Michael Feathers