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

Like this? Share it with your network

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 2

https://twitter.com 2

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide
  • 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


  • 1. Test Driven iOS Development (TDD)p ( )Md. Babul Mirdha,Senior Software Engineer, Mobile App Development,Leads Corporation Limited
  • 2. ContentsProgrammer life without Automated Unit Testing.g gWhst is xUnit?What is TDD?TDD is about Design, not Testing!Demo
  • 3. Programmer life without Automated Unit Testing
  • 4. 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
  • 5. Manual Testingmore expensive and time consumingp gbecomes boringnot reusableprovide limited Visibility and have to be repeated byall Stakeholders
  • 6. Automated TestingReusableEnsures repeatability (missing out)Drives cleaner designgProvide a Safety Net for RefactoringUp-to-date specification documentp p f
  • 7. 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
  • 8. 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.
  • 9. 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)
  • 10. 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
  • 11. Principle of TDDKent Beck defines:Never write a single line of code unless you have a failingautomated test.Eliminate duplication.TDD = TFA+ Refactoring.
  • 12. Red/Green/RefactorRed (Automated test fail)( )Green (Automated test pass because dev code hasbeen written)Refactor (Eliminate duplication, Clean the code)RedRefactorGreed
  • 13. 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
  • 14. TDD in practiceAny program featurewithout an automated testi l d ’ isimply doesn’t exist- Kent Beck- Kent Beck
  • 15. 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
  • 16. 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.
  • 17. 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 );}}
  • 18. 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.
  • 19. 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
  • 20. 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
  • 21. 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
  • 22. Test-Drive ASP.NET MVCby Jonathan McCracken
  • 23. 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
  • 24. Organization of TestsCaluculatorSenTestingKit FrameworkFramesorkProjectSenTestingKit.FrameworkDev TargetTest TargetDevelopmentCode Test Code
  • 25. 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.
  • 26. 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.
  • 27. 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
  • 28. 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
  • 29. 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");}}
  • 30. -(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
  • 31. If it doesn’t have automated unit tests, is not done.
  • 32. Then we will get …
  • 33. 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
  • 34. Q & AQ & A
  • 35. Th k T AllThanks To All