SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
Test Driven iOS Development (TDD)p ( )
Md. Babul Mirdha,
Senior Software Engineer, Mobile App Development,
Leads Corporation Limited
Contents
Programmer life without Automated Unit Testing.g g
Whst is xUnit?
What is TDD?
TDD is about Design, not Testing!
Demo
Programmer life without Automated Unit Testing
Programmer life without Unit Testing
Quickly write a lot of codeQ y
someday ... something doesn’t work or stops working
Fixing a bug is easy...
But finding the bug is a nightmare
Spend hours and days in front of the debugger
Fixing one could break other partsFixing one could break other parts
The bug could appear again later
Manual Testing
more expensive and time consumingp g
becomes boring
not reusable
provide limited Visibility and have to be repeated by
all Stakeholders
Automated Testing
Reusable
Ensures repeatability (missing out)
Drives cleaner designg
Provide a Safety Net for Refactoring
Up-to-date specification documentp p f
Need a safety guard : Poka-Yoke
Poka-yoke is a Japanese term that means "mistake-proofing“,
purpose is to eliminate product defects by preventing, correcting.
The concept was formalised, and the term adopted, by Shigeo
Shingo, who considered himself as the world’s leading expert on
manufacturing practices and the Toyota Production System
What is xUnit?
xUuit
By keeping automated testing code, programmers can verify
that they haven't broken something along the way.
xUnit is a Poka Yoke for software developmentxUnit is a Poka-Yoke for software development.
xUnit Tools
Many xUnit frameworks exist for variousy
programming languages and development platforms.
- .Net >> Nunit
i- Java >> Junit
- PHP>> Simple Test/ PHPUnit
- C++ >> gUnitC++ >> gUnit
- Python >> PyUnit
- Ruby >> Test::Unit
Objective-C >>OCUnit (SenTestingKit.Frameork)
What is TDD?
An iterative & incremental technique to develop software.
One must first write a test that fails before writing a new
functional code.
A practice for efficiently developing useful code
Principle of TDD
Kent Beck defines:
Never write a single line of code unless you have a failing
automated test.
Eliminate duplication.
TDD = TFA+ Refactoring.
Red/Green/Refactor
Red (Automated test fail)( )
Green (Automated test pass because dev code has
been written)
Refactor (Eliminate duplication, Clean the code)
Red
Refactor
Greed
What is Refactoring?
A series of Disciplined small steps, each of which changes theA series of Disciplined small steps, each of which changes the
program’s internal structure without changing its
external behavior, in order to improve some of theexternal behavior, in order to improve some of the
nonfunctional attributes of the software .
Wh d f t i tWhen need refactoring to:
Eliminate duplication
Requirement changes
Apply new design patternApply new design pattern
Rename class, object, variable & method names
Performance Optimization
Migrate to new technology.g gy
TDD in practice
Any program feature
without an automated test
i l d ’ isimply doesn’t exist
- Kent Beck- Kent Beck
Principle of TDD (In Practice)
Start
TDD Rhythm: Test-> Code-> Refactor
Red
Write a Test
h
TDD Rhythm: Test-> Code-> Refactor
Green
Run the Test
See it fail, because
there’s no dev code
Refactor
Make a little change
(Dev Code) to compile
fail
Run the Test
pass
Refactoring
p
How to Write a Test
The AAA or 3A Pattern for Unit Tests –3
Arrange: Set up data for the test.
Act: Perform the action of the test.
A V if h l f hAssert: Verify the result of the test.
How to Write a Test
Here is a simple unit test that follows the AAAp
pattern:
-(void) testMax() {
// Arrange
int x = 1;
int y = 2;
// Act
int result = [Math maxBetween: x And: y )];
// Assert
STAssertEquals( result,y );
}}
Test is NOT a Unit Test
if it _
has External Dependencies
can't run at the same time as any of other unit tests
h O d D d i O l k h i ihas Order Dependencies - Only works when run in certain
order
h b d di.e. Each Test must be independent.
TDD is about Design, not Testing!
Produces the simplest thing that works (but not the dumbest!)
Keeps it Simple And Short
Drives the design of the software through tests
Focuses on writing simple solutions for today’s requirementsg p y q
Writes just enough code to make the tests pass, and no more
Executable Test codes become requirement
TDD makes clean code that works
How does TDD achieve this?
Predictable – Tells you when you are done or not
Learn – Teaches me all lessons that the code has to teach
Confidence – Green bar gives you more confidenceConfidence Green bar gives you more confidence
Documentation – Good starting point to understand code
Protection – Puts a test- harness (yoke) around your code
Advantages
Tests _
Keep me out of the (time hungry) debugger!
Make Faster Development by eliminating Waste
R d B i N F d i E i i FReduce Bugs in New Features and in Existing Features
Reduce Cost of Change
If break some part, Red Bar appearIf break some part, Red Bar appear
Allow Refactoring, improve Design
Build a safety net and defend Against Other
PProgrammers
Force me to Slow Down and Think
Executable documentationExecutable documentation
Test-Drive ASP.NET MVC
by Jonathan McCracken
Research undertaken by Microsoft in conjunction
with IBM
Research undertaken by Microsoft in conjunction with
(h // h i f /IBM (http://research.microsoft.com/en-
us/groups/ese/nagappan_tdd.pdf)
Case studies were conducted with three developmentCase studies were conducted with three development
teams at Microsoft and one at IBM that have adopted
TDD.
The results of the case studies indicate that the preThe results of the case studies indicate that the pre-
release defect density of the four products decreased
between 40% and 90% relative to similar projects that
did t th TDD tidid not use the TDD practice.
Subjectively, the teams experienced a 15–35% increase in
initial development time after adopting TDD.p p g
Organization of Tests
Caluculator
SenTestingKit Framework
Framesork
Project
SenTestingKit.Framework
Dev Target
Test Target
Development
Code Test Code
Assertions
If an assertion fails, then an error is reported.
If a test contains multiple assertions, any that follow the one that failed
will not be executed.
For this reason, it's usually best to try for one assertion per test.
Some Asset Functions
STAssertEquals(a1, a2, msg, ...)q ( , , g, )
The arguments a1 and a2 are C datatypes (for example,
primitive values or structs) of the same type with equal values.
STAssertEquals (a1, a2, accuracy, msg, ...)
WithAccuracy The C scalar values a1 and a2 are of the sameWithAccuracy The C scalar values a1 and a2 are of the same
type and have the same value to within ±accuracy.
Quick Demo on TDD with Temperature Converter
Tools used for this demo:
- IDE : xCode
- Language : Objective-C
U i T i T l S T i Ki F k- Unit Testing Tool: SenTestingKit.Framework
- Refactoring Tool: xCode Refactor
The Requirementq
Converts the Temperature: Celsius to
Fahrenheit.
We know that
40ºC is the same as 40ºF–40ºC is the same as –40ºF
30ºC is the same as 86ºF
TestCase: –40ºC is the same as –40ºF
@implementation TemperatureConverterTests
-(void) testThatMinusFortyCelsiusIsMinusFortyFahrenheit {
//Arrange
int celciousValue=-40;
int expectedFarenheitValue=-40;int expectedFarenheitValue 40;
TemperatureConverter *converter= [[TemperatureConverter alloc] init];
//Act
int actualFarenheitValue =[converter getFahrenhitFromCelcious:celciousValue];
//Assert
STAssertEquals(actualFarenheitValue, expectedFarenheitValue,@"Did not match with Minus
Forty Celsius and Minus Forty Fahrenheit");
}}
-(void) testThat30CelsiusIs86Fahrenheit {
//Arrange
int celciousValue=30;
int expectedFarenheitValue=86;
TemperatureConverter *converter= [[TemperatureConverter alloc] init];
//Act
int actualFarenheitValue =[converter getFahrenhitFromCelcious:celciousValue];
//Assert
STAssertEquals(actualFarenheitValue expectedFarenheitValue @"Did not matchSTAssertEquals(actualFarenheitValue, expectedFarenheitValue,@ Did not match
with Minus Forty Celsius and Minus Forty Fahrenheit");
}
d@end
If it doesn’t have automated unit tests, is not done.
Then we will get …
References
Kent Beck: Test-Driven Development: By Example, Addison-
Wesley 2002Wesley, 2002.
Test-Driven iOS Development by Graham Lee
Test Driven .NET Development with FitNesse, Gojko Adzic
Test-Driven Development in Microsoft NET by James W NewkirkTest Driven Development in Microsoft .NET by James W. Newkirk
and Alexei A. Vorontsov
http://www.slideshare.net/nashjain/acceptance-test-driven-development-350264
http://blogs.agilefaqs.com/
http://www objectwind com/present/FitNesse htmhttp://www.objectwind.com/present/FitNesse.htm
http://www.xprogramming.com/software.htm
http://testdrivendeveloper.com/
http://fit.c2.com/
h //fi / iki i l dhttp://fit.c2.com/wiki.cgi?JavaDownloads
http://fit.c2.com/wiki.cgi?DotNetDownloads
http://fitnesse.org/
http://sourceforge.net/projects/fitnesse
Q & AQ & A
Th k T AllThanks To All

Más contenido relacionado

La actualidad más candente

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguestc8093a6
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) CodeOps Technologies LLP
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentJohn Blum
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 
Agile Test Driven Development
Agile Test Driven DevelopmentAgile Test Driven Development
Agile Test Driven DevelopmentViraf Karai
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development CodeOps Technologies LLP
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentMireia Sangalo
 
Test driven development
Test driven developmentTest driven development
Test driven developmentNascenia IT
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven DevelopmentTung Nguyen Thanh
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqXPDays
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010guest5639fa9
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentShawn Jones
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefAhmed Shreef
 
TDD That Was Easy!
TDD   That Was Easy!TDD   That Was Easy!
TDD That Was Easy!Kaizenko
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Mohamed Taman
 

La actualidad más candente (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Agile Test Driven Development
Agile Test Driven DevelopmentAgile Test Driven Development
Agile Test Driven Development
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Automation and Technical Debt
Automation and Technical DebtAutomation and Technical Debt
Automation and Technical Debt
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and Moq
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
TDD That Was Easy!
TDD   That Was Easy!TDD   That Was Easy!
TDD That Was Easy!
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
Test driven development
Test driven developmentTest driven development
Test driven development
 

Similar a Test Driven iOS Development (TDD)

Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Ukraine
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentbhochhi
 
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
 
Test driven development
Test driven developmentTest driven development
Test driven developmentlukaszkujawa
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In ActionJon Kruger
 
Test driven development
Test driven developmentTest driven development
Test driven developmentShalabh Saxena
 
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
 
TDD - A Reminder of the Principles
TDD - A Reminder of the PrinciplesTDD - A Reminder of the Principles
TDD - A Reminder of the PrinciplesMatthias Noback
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis Engineering Software Lab
 
How to complement TDD with static analysis
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysisPVS-Studio
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentEffective
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentJohn Blanco
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentEffectiveUI
 
Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded cBenux Wei
 

Similar a Test Driven iOS Development (TDD) (20)

TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
Python and test
Python and testPython and test
Python and test
 
tem7
tem7tem7
tem7
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
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)
 
TDD - A Reminder of the Principles
TDD - A Reminder of the PrinciplesTDD - A Reminder of the Principles
TDD - A Reminder of the Principles
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
 
How to complement TDD with static analysis
How to complement TDD with static analysisHow to complement TDD with static analysis
How to complement TDD with static analysis
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded c
 

Más de Babul Mirdha

Water Transport Safety
Water Transport SafetyWater Transport Safety
Water Transport SafetyBabul Mirdha
 
iOS App Development with Storyboard
iOS App Development with StoryboardiOS App Development with Storyboard
iOS App Development with StoryboardBabul Mirdha
 
Objective-C with respect to C# and Java
Objective-C with respect to C# and JavaObjective-C with respect to C# and Java
Objective-C with respect to C# and JavaBabul Mirdha
 
An Objective-C Primer
An Objective-C PrimerAn Objective-C Primer
An Objective-C PrimerBabul Mirdha
 
Startup to be iOS developer
Startup to be iOS developerStartup to be iOS developer
Startup to be iOS developerBabul Mirdha
 
Hands on training on DbFit Part-II
Hands on training on DbFit Part-IIHands on training on DbFit Part-II
Hands on training on DbFit Part-IIBabul Mirdha
 
Hands on training on DbFit Part-I
Hands on training on DbFit Part-IHands on training on DbFit Part-I
Hands on training on DbFit Part-IBabul Mirdha
 

Más de Babul Mirdha (7)

Water Transport Safety
Water Transport SafetyWater Transport Safety
Water Transport Safety
 
iOS App Development with Storyboard
iOS App Development with StoryboardiOS App Development with Storyboard
iOS App Development with Storyboard
 
Objective-C with respect to C# and Java
Objective-C with respect to C# and JavaObjective-C with respect to C# and Java
Objective-C with respect to C# and Java
 
An Objective-C Primer
An Objective-C PrimerAn Objective-C Primer
An Objective-C Primer
 
Startup to be iOS developer
Startup to be iOS developerStartup to be iOS developer
Startup to be iOS developer
 
Hands on training on DbFit Part-II
Hands on training on DbFit Part-IIHands on training on DbFit Part-II
Hands on training on DbFit Part-II
 
Hands on training on DbFit Part-I
Hands on training on DbFit Part-IHands on training on DbFit Part-I
Hands on training on DbFit Part-I
 

Último

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Último (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Test Driven iOS Development (TDD)

  • 1. Test Driven iOS Development (TDD)p ( ) Md. Babul Mirdha, Senior Software Engineer, Mobile App Development, Leads Corporation Limited
  • 2. Contents Programmer life without Automated Unit Testing.g g Whst is xUnit? What is TDD? TDD is about Design, not Testing! Demo
  • 3. Programmer life without Automated Unit Testing
  • 4. Programmer life without Unit Testing Quickly write a lot of codeQ y someday ... something doesn’t work or stops working Fixing a bug is easy... But finding the bug is a nightmare Spend hours and days in front of the debugger Fixing one could break other partsFixing one could break other parts The bug could appear again later
  • 5. Manual Testing more expensive and time consumingp g becomes boring not reusable provide limited Visibility and have to be repeated by all Stakeholders
  • 6. Automated Testing Reusable Ensures repeatability (missing out) Drives cleaner designg Provide a Safety Net for Refactoring Up-to-date specification documentp p f
  • 7. Need a safety guard : Poka-Yoke Poka-yoke is a Japanese term that means "mistake-proofing“, purpose is to eliminate product defects by preventing, correcting. The concept was formalised, and the term adopted, by Shigeo Shingo, who considered himself as the world’s leading expert on manufacturing practices and the Toyota Production System
  • 8. What is xUnit? xUuit By keeping automated testing code, programmers can verify that they haven't broken something along the way. xUnit is a Poka Yoke for software developmentxUnit is a Poka-Yoke for software development.
  • 9. xUnit Tools Many xUnit frameworks exist for variousy programming languages and development platforms. - .Net >> Nunit i- Java >> Junit - PHP>> Simple Test/ PHPUnit - C++ >> gUnitC++ >> gUnit - Python >> PyUnit - Ruby >> Test::Unit Objective-C >>OCUnit (SenTestingKit.Frameork)
  • 10. What is TDD? An iterative & incremental technique to develop software. One must first write a test that fails before writing a new functional code. A practice for efficiently developing useful code
  • 11. Principle of TDD Kent Beck defines: Never write a single line of code unless you have a failing automated test. Eliminate duplication. TDD = TFA+ Refactoring.
  • 12. Red/Green/Refactor Red (Automated test fail)( ) Green (Automated test pass because dev code has been written) Refactor (Eliminate duplication, Clean the code) Red Refactor Greed
  • 13. What is Refactoring? A series of Disciplined small steps, each of which changes theA series of Disciplined small steps, each of which changes the program’s internal structure without changing its external behavior, in order to improve some of theexternal behavior, in order to improve some of the nonfunctional attributes of the software . Wh d f t i tWhen need refactoring to: Eliminate duplication Requirement changes Apply new design patternApply new design pattern Rename class, object, variable & method names Performance Optimization Migrate to new technology.g gy
  • 14. TDD in practice Any program feature without an automated test i l d ’ isimply doesn’t exist - Kent Beck- Kent Beck
  • 15. Principle of TDD (In Practice) Start TDD Rhythm: Test-> Code-> Refactor Red Write a Test h TDD Rhythm: Test-> Code-> Refactor Green Run the Test See it fail, because there’s no dev code Refactor Make a little change (Dev Code) to compile fail Run the Test pass Refactoring p
  • 16. How to Write a Test The AAA or 3A Pattern for Unit Tests –3 Arrange: Set up data for the test. Act: Perform the action of the test. A V if h l f hAssert: Verify the result of the test.
  • 17. How to Write a Test Here is a simple unit test that follows the AAAp pattern: -(void) testMax() { // Arrange int x = 1; int y = 2; // Act int result = [Math maxBetween: x And: y )]; // Assert STAssertEquals( result,y ); }}
  • 18. Test is NOT a Unit Test if it _ has External Dependencies can't run at the same time as any of other unit tests h O d D d i O l k h i ihas Order Dependencies - Only works when run in certain order h b d di.e. Each Test must be independent.
  • 19. TDD is about Design, not Testing! Produces the simplest thing that works (but not the dumbest!) Keeps it Simple And Short Drives the design of the software through tests Focuses on writing simple solutions for today’s requirementsg p y q Writes just enough code to make the tests pass, and no more Executable Test codes become requirement
  • 20. TDD makes clean code that works How does TDD achieve this? Predictable – Tells you when you are done or not Learn – Teaches me all lessons that the code has to teach Confidence – Green bar gives you more confidenceConfidence Green bar gives you more confidence Documentation – Good starting point to understand code Protection – Puts a test- harness (yoke) around your code
  • 21. Advantages Tests _ Keep me out of the (time hungry) debugger! Make Faster Development by eliminating Waste R d B i N F d i E i i FReduce Bugs in New Features and in Existing Features Reduce Cost of Change If break some part, Red Bar appearIf break some part, Red Bar appear Allow Refactoring, improve Design Build a safety net and defend Against Other PProgrammers Force me to Slow Down and Think Executable documentationExecutable documentation
  • 22. Test-Drive ASP.NET MVC by Jonathan McCracken
  • 23. Research undertaken by Microsoft in conjunction with IBM Research undertaken by Microsoft in conjunction with (h // h i f /IBM (http://research.microsoft.com/en- us/groups/ese/nagappan_tdd.pdf) Case studies were conducted with three developmentCase studies were conducted with three development teams at Microsoft and one at IBM that have adopted TDD. The results of the case studies indicate that the preThe results of the case studies indicate that the pre- release defect density of the four products decreased between 40% and 90% relative to similar projects that did t th TDD tidid not use the TDD practice. Subjectively, the teams experienced a 15–35% increase in initial development time after adopting TDD.p p g
  • 24. Organization of Tests Caluculator SenTestingKit Framework Framesork Project SenTestingKit.Framework Dev Target Test Target Development Code Test Code
  • 25.
  • 26. Assertions If an assertion fails, then an error is reported. If a test contains multiple assertions, any that follow the one that failed will not be executed. For this reason, it's usually best to try for one assertion per test.
  • 27. Some Asset Functions STAssertEquals(a1, a2, msg, ...)q ( , , g, ) The arguments a1 and a2 are C datatypes (for example, primitive values or structs) of the same type with equal values. STAssertEquals (a1, a2, accuracy, msg, ...) WithAccuracy The C scalar values a1 and a2 are of the sameWithAccuracy The C scalar values a1 and a2 are of the same type and have the same value to within ±accuracy.
  • 28. Quick Demo on TDD with Temperature Converter Tools used for this demo: - IDE : xCode - Language : Objective-C U i T i T l S T i Ki F k- Unit Testing Tool: SenTestingKit.Framework - Refactoring Tool: xCode Refactor
  • 29. The Requirementq Converts the Temperature: Celsius to Fahrenheit. We know that 40ºC is the same as 40ºF–40ºC is the same as –40ºF 30ºC is the same as 86ºF
  • 30. TestCase: –40ºC is the same as –40ºF @implementation TemperatureConverterTests -(void) testThatMinusFortyCelsiusIsMinusFortyFahrenheit { //Arrange int celciousValue=-40; int expectedFarenheitValue=-40;int expectedFarenheitValue 40; TemperatureConverter *converter= [[TemperatureConverter alloc] init]; //Act int actualFarenheitValue =[converter getFahrenhitFromCelcious:celciousValue]; //Assert STAssertEquals(actualFarenheitValue, expectedFarenheitValue,@"Did not match with Minus Forty Celsius and Minus Forty Fahrenheit"); }}
  • 31. -(void) testThat30CelsiusIs86Fahrenheit { //Arrange int celciousValue=30; int expectedFarenheitValue=86; TemperatureConverter *converter= [[TemperatureConverter alloc] init]; //Act int actualFarenheitValue =[converter getFahrenhitFromCelcious:celciousValue]; //Assert STAssertEquals(actualFarenheitValue expectedFarenheitValue @"Did not matchSTAssertEquals(actualFarenheitValue, expectedFarenheitValue,@ Did not match with Minus Forty Celsius and Minus Forty Fahrenheit"); } d@end
  • 32. If it doesn’t have automated unit tests, is not done.
  • 33. Then we will get …
  • 34. References Kent Beck: Test-Driven Development: By Example, Addison- Wesley 2002Wesley, 2002. Test-Driven iOS Development by Graham Lee Test Driven .NET Development with FitNesse, Gojko Adzic Test-Driven Development in Microsoft NET by James W NewkirkTest Driven Development in Microsoft .NET by James W. Newkirk and Alexei A. Vorontsov http://www.slideshare.net/nashjain/acceptance-test-driven-development-350264 http://blogs.agilefaqs.com/ http://www objectwind com/present/FitNesse htmhttp://www.objectwind.com/present/FitNesse.htm http://www.xprogramming.com/software.htm http://testdrivendeveloper.com/ http://fit.c2.com/ h //fi / iki i l dhttp://fit.c2.com/wiki.cgi?JavaDownloads http://fit.c2.com/wiki.cgi?DotNetDownloads http://fitnesse.org/ http://sourceforge.net/projects/fitnesse
  • 35. Q & AQ & A
  • 36. Th k T AllThanks To All

Notas del editor

  1. http://c2.com/cgi/wiki?ArrangeActAsserthttp://www.arrangeactassert.com/why-and-what-is-arrange-act-assert/http://stackoverflow.com/questions/1021007/should-it-be-arrange-assert-act-assert