SlideShare a Scribd company logo
Unit Testing on Mobile
Apps
Buşra Deniz
busradeniz89@gmail.com
@busradeniz
Agenda
● Unit Test
● Why test your code?
● How to unit test ?
● When test your code ?
● Tools for iOS Unit Testing
● Tools for Android Unit Testing
● Demo
● Questions
Unit Test
Testing a single unit of code.
Why test your code ?
● Fix bug early
Why test your code ?
● Fix bug early
● Refine design
Why test your code ?
● Fix bug early
● Refine design
● Easier to make changes
Why test your code ?
● Fix bug early
● Refine design
● Easier to make changes
● Useful documentation
Why test your code ?
● Fix bug early
● Refine design
● Easier to make changes
● Useful documentation
● Reduce testing time
How to Unit Test ?
“Never test the depth of the water
with both feet”
When test your code ?
● After writing code
When test your code ?
● After writing code
● Before writing code
When test your code ?
● After writing code
● Before writing code
● After fixing a bug
Tools for iOS Unit Testing
● OCUnit / SenTestKit
● XCTest
● GHUnit
● OCMock
● KIF
● Specta, Frank, Kiwi, Cedar , Google ToolKit
for Mac, CATCH vs.
Test Suite
- (void) setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void) tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void) testExample {
// write your test code
XCTFail(@"No implementation for "%s"", __PRETTY_FUNCTION__);
}
XCTest Code Sample
- (void)test_PostRequestCreationWithoutHeaders
{
RestBody *restBody = [[RestBody alloc] init];
[restBody addHeaderItem:@"demoBodyKey" andValue:@"demoBodyValue"];
[restBody addHeaderItem:@"demoBodyKey2" andValue:@"demoBodyValue2"];
restPostRequest = [[RestPostRequest alloc] init:restBody andServiceUrlSuffix:serviceUrlSuffix];
XCTAssertNotNil(restPostRequest.serviceUrlSuffix, @"Service URL suffix cannot be nil");
XCTAssertNotNil(restPostRequest.messageHeader, @"Headers cannot be nil");
XCTAssertNotNil(restPostRequest.messageBody, @"Body cannot be nil");
XCTAssertEqual(serviceUrlSuffix, restPostRequest.serviceUrlSuffix, @"Service URL suffix must equal to %@" ,serviceUrlSuffix
);
XCTAssertEqual( (NSUInteger)7 , restPostRequest.messageHeader.messageHeader.allKeys.count , @"Header size is wrong");
XCTAssertEqual( (NSUInteger)2 , restPostRequest.messageBody.messageBody.allKeys.count , @"Body size is wrong");
XCTAssertTrue([restPostRequest.messageBody.messageBody objectForKey:@"demoBodyKey"], @"RestRequest body must
contain %@" , @"demoBodyKey");
}
OCMock with XCTest Code Sample
-(void) test_Connect {
id notificationComponent = [OCMockObject mockForClass:[NotificationComponent
class] ];
id notificationEngine = [OCMockObject mockForClass:[NotificationEngine class]];
[notificationEngine setNotificationComponent:notificationEngine];
[[notificationComponent expect] connect:@""];
[notificationEngine connect:@""];
[notificationEngine verify];
}
Tools for Android Unit Testing
● JUnit
● Robolectric
● Robotium
● Mockhito
● PowerMock, EasyMock vs.
JUnit with Mockhito Code Sample
public void connectTest() {
NotificationComponentInterface notificationComponent =
Mockito.mock(NotificationComponentInterface.class);
notificationEngine.setNotificationComponenent(notificationComponent);
notificationEngine.connect();
try {
Mockito.verify(notificationComponent, Mockito.times(1)).connect();
} catch (MockitoAssertionError e) {
throw new MockitoAssertionError(TAG + "notificationComponent.connect() method failed! " +
e.getMessage());
}
}
Robolectric Sample Code
public class MyActivityTest {
@Test
public void clickingButton_shouldChangeResultsViewText() throws Exception {
Activity activity = Robolectric.buildActivity(MyActivity.class).create().get();
Button pressMeButton = (Button) activity.findViewById(R.id.press_me_button);
TextView results = (TextView) activity.findViewById(R.id.results_text_view);
pressMeButton.performClick();
String resultsText = results.getText().toString();
assertThat(resultsText, equalTo("Testing Android Rocks!"));
}
}
Demo
Demo with KIF (Keep It Functional)
Questions
Resources
● Test Driven Development on iOS / Graham Lee
● www.raywenderlich.com
● http://developer.android.com
● http://developer.apple.com
Thanks ...

More Related Content

What's hot

Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Codemotion
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
Michael Haberman
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
Peter Drinnan
 
Testing javascript in the frontend
Testing javascript in the frontendTesting javascript in the frontend
Testing javascript in the frontend
Frederic CABASSUT
 
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava TalkUnit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
Long Weekend LLC
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
Scott Becker
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Avi Engelshtein
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Swtbot
SwtbotSwtbot
Swtbot
cristitep
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Alessandro Giorgetti
 
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasySwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
Ankit Goel
 
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
Alin Pandichi
 
Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"
Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"
Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"
Fwdays
 
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karmaClient side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
Adam Klein
 
Functional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and TestersFunctional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and Testers
Aurélien Pupier
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDI
Sven Ruppert
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
Rotem Tamir
 
SWTBot Tutorial
SWTBot TutorialSWTBot Tutorial
SWTBot Tutorial
Chris Aniszczyk
 

What's hot (20)

Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Testing javascript in the frontend
Testing javascript in the frontendTesting javascript in the frontend
Testing javascript in the frontend
 
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava TalkUnit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Swtbot
SwtbotSwtbot
Swtbot
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasySwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
 
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
 
Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"
Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"
Михаил Боднарчук "Acceptance Testing in NodeJS: Tools & Approaches"
 
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karmaClient side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
 
Functional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and TestersFunctional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and Testers
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
JavaFX8 TestFX - CDI
JavaFX8   TestFX - CDIJavaFX8   TestFX - CDI
JavaFX8 TestFX - CDI
 
Unit tests in node.js
Unit tests in node.jsUnit tests in node.js
Unit tests in node.js
 
SWTBot Tutorial
SWTBot TutorialSWTBot Tutorial
SWTBot Tutorial
 

Viewers also liked

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
Robot Media
 
work4-57
work4-57work4-57
work4-57
Cat Cattaleeya
 
ชุดที่ 2
ชุดที่ 2ชุดที่ 2
ชุดที่ 2
Cat Cattaleeya
 
Business Sectors & Its contribution in india
Business Sectors & Its contribution in indiaBusiness Sectors & Its contribution in india
Business Sectors & Its contribution in india
Raushan Pandey
 
ชุดที่ 1
ชุดที่ 1ชุดที่ 1
ชุดที่ 1
Cat Cattaleeya
 
Triple moinitor wall mount
Triple moinitor wall mountTriple moinitor wall mount
Triple moinitor wall mount
complement-ltd
 
work3-56
work3-56work3-56
onet-work4-56
onet-work4-56onet-work4-56
onet-work4-56
Mew Assavakarint
 
Egg shell color
Egg shell colorEgg shell color
Egg shell color
Mohsen Ali
 
Tutorial penginstalan joomla cms 2
Tutorial penginstalan joomla cms 2Tutorial penginstalan joomla cms 2
Tutorial penginstalan joomla cms 2
150399
 
Ergonomics - For Employees Satisfaction
Ergonomics - For Employees SatisfactionErgonomics - For Employees Satisfaction
Ergonomics - For Employees Satisfaction
complement-ltd
 
10 seconds Rule on 5 jan.
10 seconds Rule on 5 jan.10 seconds Rule on 5 jan.
10 seconds Rule on 5 jan.
Gettowork
 
ชุดที่ 3
ชุดที่ 3ชุดที่ 3
ชุดที่ 3
Cat Cattaleeya
 
Tarlan kajian benthic terrain ruggedness
Tarlan kajian benthic terrain ruggednessTarlan kajian benthic terrain ruggedness
Tarlan kajian benthic terrain ruggedness
allan_awani
 
Company profli upgrade litle
Company profli upgrade litleCompany profli upgrade litle
Company profli upgrade litle
upgrade graphic design
 
work3-57
work3-57work3-57
work3-57
Cat Cattaleeya
 
Psikometri - optimisme
Psikometri - optimismePsikometri - optimisme
Psikometri - optimisme
Anita Endah P
 
Multimedia_Interaktif
Multimedia_InteraktifMultimedia_Interaktif
Multimedia_Interaktif
audina20
 
เทคโนโลยีคอมพิวเตอร์
เทคโนโลยีคอมพิวเตอร์เทคโนโลยีคอมพิวเตอร์
เทคโนโลยีคอมพิวเตอร์
Unyas
 
IT-07-22
IT-07-22IT-07-22
IT-07-22
Unyas
 

Viewers also liked (20)

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
 
work4-57
work4-57work4-57
work4-57
 
ชุดที่ 2
ชุดที่ 2ชุดที่ 2
ชุดที่ 2
 
Business Sectors & Its contribution in india
Business Sectors & Its contribution in indiaBusiness Sectors & Its contribution in india
Business Sectors & Its contribution in india
 
ชุดที่ 1
ชุดที่ 1ชุดที่ 1
ชุดที่ 1
 
Triple moinitor wall mount
Triple moinitor wall mountTriple moinitor wall mount
Triple moinitor wall mount
 
work3-56
work3-56work3-56
work3-56
 
onet-work4-56
onet-work4-56onet-work4-56
onet-work4-56
 
Egg shell color
Egg shell colorEgg shell color
Egg shell color
 
Tutorial penginstalan joomla cms 2
Tutorial penginstalan joomla cms 2Tutorial penginstalan joomla cms 2
Tutorial penginstalan joomla cms 2
 
Ergonomics - For Employees Satisfaction
Ergonomics - For Employees SatisfactionErgonomics - For Employees Satisfaction
Ergonomics - For Employees Satisfaction
 
10 seconds Rule on 5 jan.
10 seconds Rule on 5 jan.10 seconds Rule on 5 jan.
10 seconds Rule on 5 jan.
 
ชุดที่ 3
ชุดที่ 3ชุดที่ 3
ชุดที่ 3
 
Tarlan kajian benthic terrain ruggedness
Tarlan kajian benthic terrain ruggednessTarlan kajian benthic terrain ruggedness
Tarlan kajian benthic terrain ruggedness
 
Company profli upgrade litle
Company profli upgrade litleCompany profli upgrade litle
Company profli upgrade litle
 
work3-57
work3-57work3-57
work3-57
 
Psikometri - optimisme
Psikometri - optimismePsikometri - optimisme
Psikometri - optimisme
 
Multimedia_Interaktif
Multimedia_InteraktifMultimedia_Interaktif
Multimedia_Interaktif
 
เทคโนโลยีคอมพิวเตอร์
เทคโนโลยีคอมพิวเตอร์เทคโนโลยีคอมพิวเตอร์
เทคโนโลยีคอมพิวเตอร์
 
IT-07-22
IT-07-22IT-07-22
IT-07-22
 

Similar to Unit testing on mobile apps

Art of unit testing: how to do it right
Art of unit testing: how to do it rightArt of unit testing: how to do it right
Art of unit testing: how to do it right
Dmytro Patserkovskyi
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOS
Ciklum Ukraine
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
Dror Helper
 
Unit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and HowsUnit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and Hows
atesgoral
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
Mats Bryntse
 
Test driven development
Test driven developmentTest driven development
Test driven development
christoforosnalmpantis
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
ICS
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
Gianluca Padovani
 
Refactor your way forward
Refactor your way forwardRefactor your way forward
Refactor your way forward
Jorge Ortiz
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik Ebbers
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats Bryntse
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
Ortus Solutions, Corp
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
Dror Helper
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
Gianluca Padovani
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
Python and test
Python and testPython and test
Python and test
Micron Technology
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
pleeps
 
A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)
Thierry Gayet
 

Similar to Unit testing on mobile apps (20)

Art of unit testing: how to do it right
Art of unit testing: how to do it rightArt of unit testing: how to do it right
Art of unit testing: how to do it right
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOS
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Unit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and HowsUnit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and Hows
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Refactor your way forward
Refactor your way forwardRefactor your way forward
Refactor your way forward
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Python and test
Python and testPython and test
Python and test
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)
 

More from Buşra Deniz, CSM

SDP (Session Description Protocol)
SDP (Session Description Protocol)SDP (Session Description Protocol)
SDP (Session Description Protocol)
Buşra Deniz, CSM
 
HealthKit
HealthKitHealthKit
Mobile Software Testing Challenges
Mobile Software Testing ChallengesMobile Software Testing Challenges
Mobile Software Testing Challenges
Buşra Deniz, CSM
 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015
Buşra Deniz, CSM
 
WebRTC on Mobile
WebRTC on MobileWebRTC on Mobile
WebRTC on Mobile
Buşra Deniz, CSM
 
Game development via_sprite_kit
Game development via_sprite_kitGame development via_sprite_kit
Game development via_sprite_kit
Buşra Deniz, CSM
 

More from Buşra Deniz, CSM (6)

SDP (Session Description Protocol)
SDP (Session Description Protocol)SDP (Session Description Protocol)
SDP (Session Description Protocol)
 
HealthKit
HealthKitHealthKit
HealthKit
 
Mobile Software Testing Challenges
Mobile Software Testing ChallengesMobile Software Testing Challenges
Mobile Software Testing Challenges
 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015
 
WebRTC on Mobile
WebRTC on MobileWebRTC on Mobile
WebRTC on Mobile
 
Game development via_sprite_kit
Game development via_sprite_kitGame development via_sprite_kit
Game development via_sprite_kit
 

Recently uploaded

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 

Recently uploaded (20)

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 

Unit testing on mobile apps

  • 1. Unit Testing on Mobile Apps Buşra Deniz busradeniz89@gmail.com @busradeniz
  • 2. Agenda ● Unit Test ● Why test your code? ● How to unit test ? ● When test your code ? ● Tools for iOS Unit Testing ● Tools for Android Unit Testing ● Demo ● Questions
  • 3. Unit Test Testing a single unit of code.
  • 4. Why test your code ? ● Fix bug early
  • 5. Why test your code ? ● Fix bug early ● Refine design
  • 6. Why test your code ? ● Fix bug early ● Refine design ● Easier to make changes
  • 7. Why test your code ? ● Fix bug early ● Refine design ● Easier to make changes ● Useful documentation
  • 8. Why test your code ? ● Fix bug early ● Refine design ● Easier to make changes ● Useful documentation ● Reduce testing time
  • 9. How to Unit Test ? “Never test the depth of the water with both feet”
  • 10. When test your code ? ● After writing code
  • 11. When test your code ? ● After writing code ● Before writing code
  • 12. When test your code ? ● After writing code ● Before writing code ● After fixing a bug
  • 13. Tools for iOS Unit Testing ● OCUnit / SenTestKit ● XCTest ● GHUnit ● OCMock ● KIF ● Specta, Frank, Kiwi, Cedar , Google ToolKit for Mac, CATCH vs.
  • 14. Test Suite - (void) setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class. } - (void) tearDown { // Put teardown code here. This method is called after the invocation of each test method in the class. [super tearDown]; } - (void) testExample { // write your test code XCTFail(@"No implementation for "%s"", __PRETTY_FUNCTION__); }
  • 15. XCTest Code Sample - (void)test_PostRequestCreationWithoutHeaders { RestBody *restBody = [[RestBody alloc] init]; [restBody addHeaderItem:@"demoBodyKey" andValue:@"demoBodyValue"]; [restBody addHeaderItem:@"demoBodyKey2" andValue:@"demoBodyValue2"]; restPostRequest = [[RestPostRequest alloc] init:restBody andServiceUrlSuffix:serviceUrlSuffix]; XCTAssertNotNil(restPostRequest.serviceUrlSuffix, @"Service URL suffix cannot be nil"); XCTAssertNotNil(restPostRequest.messageHeader, @"Headers cannot be nil"); XCTAssertNotNil(restPostRequest.messageBody, @"Body cannot be nil"); XCTAssertEqual(serviceUrlSuffix, restPostRequest.serviceUrlSuffix, @"Service URL suffix must equal to %@" ,serviceUrlSuffix ); XCTAssertEqual( (NSUInteger)7 , restPostRequest.messageHeader.messageHeader.allKeys.count , @"Header size is wrong"); XCTAssertEqual( (NSUInteger)2 , restPostRequest.messageBody.messageBody.allKeys.count , @"Body size is wrong"); XCTAssertTrue([restPostRequest.messageBody.messageBody objectForKey:@"demoBodyKey"], @"RestRequest body must contain %@" , @"demoBodyKey"); }
  • 16. OCMock with XCTest Code Sample -(void) test_Connect { id notificationComponent = [OCMockObject mockForClass:[NotificationComponent class] ]; id notificationEngine = [OCMockObject mockForClass:[NotificationEngine class]]; [notificationEngine setNotificationComponent:notificationEngine]; [[notificationComponent expect] connect:@""]; [notificationEngine connect:@""]; [notificationEngine verify]; }
  • 17. Tools for Android Unit Testing ● JUnit ● Robolectric ● Robotium ● Mockhito ● PowerMock, EasyMock vs.
  • 18. JUnit with Mockhito Code Sample public void connectTest() { NotificationComponentInterface notificationComponent = Mockito.mock(NotificationComponentInterface.class); notificationEngine.setNotificationComponenent(notificationComponent); notificationEngine.connect(); try { Mockito.verify(notificationComponent, Mockito.times(1)).connect(); } catch (MockitoAssertionError e) { throw new MockitoAssertionError(TAG + "notificationComponent.connect() method failed! " + e.getMessage()); } }
  • 19. Robolectric Sample Code public class MyActivityTest { @Test public void clickingButton_shouldChangeResultsViewText() throws Exception { Activity activity = Robolectric.buildActivity(MyActivity.class).create().get(); Button pressMeButton = (Button) activity.findViewById(R.id.press_me_button); TextView results = (TextView) activity.findViewById(R.id.results_text_view); pressMeButton.performClick(); String resultsText = results.getText().toString(); assertThat(resultsText, equalTo("Testing Android Rocks!")); } }
  • 20. Demo Demo with KIF (Keep It Functional)
  • 22. Resources ● Test Driven Development on iOS / Graham Lee ● www.raywenderlich.com ● http://developer.android.com ● http://developer.apple.com Thanks ...