Test Driven iOS Development (TDD)
Upcoming SlideShare
Loading in...5
×
 

Test Driven iOS Development (TDD)

on

  • 3,365 views

 

Statistics

Views

Total Views
3,365
Views on SlideShare
3,363
Embed Views
2

Actions

Likes
3
Downloads
35
Comments
2

1 Embed 2

https://twitter.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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

Test Driven iOS Development (TDD) Test Driven iOS Development (TDD) Presentation Transcript

  • Test Driven iOS Development (TDD)p ( )Md. Babul Mirdha,Senior Software Engineer, Mobile App Development,Leads Corporation Limited
  • ContentsProgrammer life without Automated Unit Testing.g gWhst is xUnit?What is TDD?TDD is about Design, not Testing!Demo
  • Programmer life without Automated Unit Testing
  • Programmer life without Unit TestingQuickly write a lot of codeQ ysomeday ... something doesn’t work or stops workingFixing a bug is easy...But finding the bug is a nightmareSpend hours and days in front of the debuggerFixing one could break other partsFixing one could break other partsThe bug could appear again later
  • Manual Testingmore expensive and time consumingp gbecomes boringnot reusableprovide limited Visibility and have to be repeated byall Stakeholders
  • Automated TestingReusableEnsures repeatability (missing out)Drives cleaner designgProvide a Safety Net for RefactoringUp-to-date specification documentp p f
  • Need a safety guard : Poka-YokePoka-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 ShigeoShingo, who considered himself as the world’s leading expert onmanufacturing practices and the Toyota Production System
  • What is xUnit?xUuitBy keeping automated testing code, programmers can verifythat they havent broken something along the way.xUnit is a Poka Yoke for software developmentxUnit is a Poka-Yoke for software development.
  • xUnit ToolsMany xUnit frameworks exist for variousyprogramming languages and development platforms.- .Net >> Nuniti- Java >> Junit- PHP>> Simple Test/ PHPUnit- C++ >> gUnitC++ >> gUnit- Python >> PyUnit- Ruby >> Test::UnitObjective-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 newfunctional code.A practice for efficiently developing useful code
  • Principle of TDDKent Beck defines:Never write a single line of code unless you have a failingautomated test.Eliminate duplication.TDD = TFA+ Refactoring.
  • Red/Green/RefactorRed (Automated test fail)( )Green (Automated test pass because dev code hasbeen written)Refactor (Eliminate duplication, Clean the code)RedRefactorGreed
  • What is Refactoring?A series of Disciplined small steps, each of which changes theA series of Disciplined small steps, each of which changes theprogram’s internal structure without changing itsexternal behavior, in order to improve some of theexternal behavior, in order to improve some of thenonfunctional attributes of the software .Wh d f t i tWhen need refactoring to:Eliminate duplicationRequirement changesApply new design patternApply new design patternRename class, object, variable & method namesPerformance OptimizationMigrate to new technology.g gy
  • TDD in practiceAny program featurewithout an automated testi l d ’ isimply doesn’t exist- Kent Beck- Kent Beck
  • Principle of TDD (In Practice)StartTDD Rhythm: Test-> Code-> RefactorRedWrite a TesthTDD Rhythm: Test-> Code-> RefactorGreenRun the TestSee it fail, becausethere’s no dev codeRefactorMake a little change(Dev Code) to compilefailRun the TestpassRefactoringp
  • How to Write a TestThe AAA or 3A Pattern for Unit Tests –3Arrange: 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 TestHere is a simple unit test that follows the AAAppattern:-(void) testMax() {// Arrangeint x = 1;int y = 2;// Actint result = [Math maxBetween: x And: y )];// AssertSTAssertEquals( result,y );}}
  • Test is NOT a Unit Testif it _has External Dependenciescant run at the same time as any of other unit testsh O d D d i O l k h i ihas Order Dependencies - Only works when run in certainorderh 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 ShortDrives the design of the software through testsFocuses on writing simple solutions for today’s requirementsg p y qWrites just enough code to make the tests pass, and no moreExecutable Test codes become requirement
  • TDD makes clean code that worksHow does TDD achieve this?Predictable – Tells you when you are done or notLearn – Teaches me all lessons that the code has to teachConfidence – Green bar gives you more confidenceConfidence Green bar gives you more confidenceDocumentation – Good starting point to understand codeProtection – Puts a test- harness (yoke) around your code
  • AdvantagesTests _Keep me out of the (time hungry) debugger!Make Faster Development by eliminating WasteR d B i N F d i E i i FReduce Bugs in New Features and in Existing FeaturesReduce Cost of ChangeIf break some part, Red Bar appearIf break some part, Red Bar appearAllow Refactoring, improve DesignBuild a safety net and defend Against OtherPProgrammersForce me to Slow Down and ThinkExecutable documentationExecutable documentation
  • Test-Drive ASP.NET MVCby Jonathan McCracken
  • Research undertaken by Microsoft in conjunctionwith IBMResearch 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 developmentteams at Microsoft and one at IBM that have adoptedTDD.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 decreasedbetween 40% and 90% relative to similar projects thatdid t th TDD tidid not use the TDD practice.Subjectively, the teams experienced a 15–35% increase ininitial development time after adopting TDD.p p g
  • Organization of TestsCaluculatorSenTestingKit FrameworkFramesorkProjectSenTestingKit.FrameworkDev TargetTest TargetDevelopmentCode Test Code
  • AssertionsIf an assertion fails, then an error is reported.If a test contains multiple assertions, any that follow the one that failedwill not be executed.For this reason, its usually best to try for one assertion per test.
  • Some Asset FunctionsSTAssertEquals(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 sametype and have the same value to within ±accuracy.
  • Quick Demo on TDD with Temperature ConverterTools used for this demo:- IDE : xCode- Language : Objective-CU i T i T l S T i Ki F k- Unit Testing Tool: SenTestingKit.Framework- Refactoring Tool: xCode Refactor
  • The RequirementqConverts the Temperature: Celsius toFahrenheit.We know that40ºC is the same as 40ºF–40ºC is the same as –40ºF30ºC is the same as 86ºF
  • TestCase: –40ºC is the same as –40ºF@implementation TemperatureConverterTests-(void) testThatMinusFortyCelsiusIsMinusFortyFahrenheit {//Arrangeint celciousValue=-40;int expectedFarenheitValue=-40;int expectedFarenheitValue 40;TemperatureConverter *converter= [[TemperatureConverter alloc] init];//Actint actualFarenheitValue =[converter getFahrenhitFromCelcious:celciousValue];//AssertSTAssertEquals(actualFarenheitValue, expectedFarenheitValue,@"Did not match with MinusForty Celsius and Minus Forty Fahrenheit");}}
  • -(void) testThat30CelsiusIs86Fahrenheit {//Arrangeint celciousValue=30;int expectedFarenheitValue=86;TemperatureConverter *converter= [[TemperatureConverter alloc] init];//Actint actualFarenheitValue =[converter getFahrenhitFromCelcious:celciousValue];//AssertSTAssertEquals(actualFarenheitValue expectedFarenheitValue @"Did not matchSTAssertEquals(actualFarenheitValue, expectedFarenheitValue,@ Did not matchwith Minus Forty Celsius and Minus Forty Fahrenheit");}d@end
  • If it doesn’t have automated unit tests, is not done.
  • Then we will get …
  • ReferencesKent Beck: Test-Driven Development: By Example, Addison-Wesley 2002Wesley, 2002.Test-Driven iOS Development by Graham LeeTest Driven .NET Development with FitNesse, Gojko AdzicTest-Driven Development in Microsoft NET by James W NewkirkTest Driven Development in Microsoft .NET by James W. Newkirkand Alexei A. Vorontsovhttp://www.slideshare.net/nashjain/acceptance-test-driven-development-350264http://blogs.agilefaqs.com/http://www objectwind com/present/FitNesse htmhttp://www.objectwind.com/present/FitNesse.htmhttp://www.xprogramming.com/software.htmhttp://testdrivendeveloper.com/http://fit.c2.com/h //fi / iki i l dhttp://fit.c2.com/wiki.cgi?JavaDownloadshttp://fit.c2.com/wiki.cgi?DotNetDownloadshttp://fitnesse.org/http://sourceforge.net/projects/fitnesse
  • Q & AQ & A
  • Th k T AllThanks To All