SlideShare a Scribd company logo
TDD Code Kata 1

  StringCalculator
Ground Rules
● do not skip ahead

● no man left behind

● we will only get as far as the whole group gets by 12:50 to
  allow for discussion at the end

● when we're out of time, that's it

● next time, start from beginning again, not where we left off

● if participating, commit and obey the rules

● if observing, please do not assist or distract
Review Requirement

There should be a StringCalculator application
Compose Test

there should be a StringCalculator

● Launch FlashBuilder

● Create an application to run unit tests

● Create a new Flex Desktop Project called
  StringCalculatorTestRunner in your kata directory

● Add the FlexUnit swc's to to libs

● Add a class named Suite to a package named 'suite'

● Add a class named Test to a package named 'test'
Compose Test
there should be a StringCalculator

  ● add flexui:TestRunnerBase component to the test application
  ● add creationComplete handler to instantiate, init & run FlexUnitCore

<s:WindowedApplication    xmlns:fx="http://ns.adobe.com/mxml/2009"
                            xmlns:s="library://ns.adobe.com/flex/spark"
                            xmlns:mx="library://ns.adobe.com/flex/mx"
                            xmlns:flexui="org.flexunit.flexui.*"
                            width="1200" height="900"
                            creationComplete="application1_creationCompleteHandler(event)">
     <fx:Script>
           <![CDATA[
                 import mx.events.FlexEvent;
                 import org.flexunit.runner.FlexUnitCore;
                 import suite.Suite;

                 protected function application1_creationCompleteHandler(event:FlexEvent):void{
                       var core:FlexUnitCore = new FlexUnitCore();
                       core.addListener(myRunnerBase);
                       core.run(suite.Suite);
                 }
            ]]>
      </fx:Script>
      <flexui:TestRunnerBase id="myRunnerBase" />
</s:WindowedApplication>
Compose Test

there should be a StringCalculator

● Edit the Suite class

            package suite{
               import tests.Test;

                [Suite]
                [RunWith("org.flexunit.runners.Suite")]
                public class Suite{
                    public var test:Test;
                }
            }
Compose Test
there should be a StringCalculator

● Edit the Test class: add a passing test to get started

          package tests{

              import org.flexunit.Assert;

              public class Test{

                  [Test]
                  public function Run_App_CompilesWithoutError():void{
                         var expected:Number = 3;
                      var actual:Number = Math.round(3.4999999);
                      Assert.assertEquals(expected, actual);
                  }
              }
          }
Develop

there should be a StringCalculator

● Create a directory on your computer for this kata project:
  kata/StringCalculator

● Create a new ActionScript web project called
  StringCalculator in your directory with default settings

● In Test App's Project Properties>Build Path>Source Path,
  add your StringCalculator project's src directory

● Run the test app, resolve any compiler issues

● See starter test pass
Review Requirement

StringCalculator should have an add() function that:

● returns a Number

● accepts a String

● returns 0 for an empty string
Compose Test

add() should exist and return 0 for empty string

● add a test called 'Add_InputEmptyString_ReturnsZero'

● instantiate the StringCalculator class

● call StringCalculator.add()

● Command+1 to 'create method add'

● run StringCalculatorTestRunner

● see test fail
Develop

add() should exist and return 0 for empty string

● add a String parameter: add(numbers:String)

● add a return type of Number: add():Number

● add statements: var sum:Number; return sum;
Compose Test

add() should exist and return 0 for empty string

● assert that 0 is returned for an empty string

● run StringCalclatorTestRunner

● see test fail
Develop

add() should exist and return 0 for empty string

● add a condition where empty string returns 0

● run StringCalclatorTestRunner

● see test pass



Congratulations!
Your first requirement is formally specified
Your application's intent is formally documented
Your application works as expected
Review Requirement

The calculator's add function should:

● throw exception for more than 2 inputs

● return the value of 1 valid input

● return the sum of 2 valid inputs
Compose Test

throw exception for more than 2 inputs

● move StringCalculator to class and create in [Before]

● add test called
  'Add_InputMoreThanTwoValues_ThrowsError'

● compose the test and it's assertion

● run StringCalclatorTestRunner

● see test fail
Develop

throw exception for more than 2 inputs

● add a condition where too many inputs throws an error

● run StringCalclatorTestRunner

● see all tests pass
Compose Test

return the value of 1 valid input

● add test called 'Add_InputSingleValue_ReturnsInputValue'

● compose the test and it's assertion

● run StringCalclatorTestRunner

● see test fail
Develop

return the value of 1 valid input

● add condition where single input value is returned

● run StringCalclatorTestRunner

● see all tests pass
Compose Test

return the sum of 2 valid inputs

● add test called 'Add_InputTwoValues_ReturnsSum'

● compose the test and it's assertion

● run StringCalclatorTestRunner

● see test fail
Develop

return the sum of 2 valid inputs

● add condition where sum of two inputs is returned

● run StringCalclatorTestRunner

● see all tests pass
Review Requirement

The calculator's add function should return the sum of any
number of inputs




Here is a great example of how requirements change on us
UnitTests help us to refactor code, safely and with confidence
Compose Test

return the sum of any number of inputs

● [Ignore] 'Add_InputMoreThanTwoValues_ThrowsError'

● add test called
  'Add_InputMoreThanTwoValues_ReturnsSum'

● compose the test and it's assertion

● run StringCalclatorTestRunner

● see test fail
Develop

return the sum of any number of inputs

● remove condition where more than two inputs throws an
  error

● add condition and logic to add any number of inputs

● run StringCalclatorTestRunner

● see all tests pass
Review Requirement

The calculator's add function should:

● accept the new line character 'n' as a delimeter

● 'n' and ',' are allowed in the same input: add('1n2,3')
Compose Test

accept the new line character 'n' as a delimiter

● add test called
  'Add_InputsDelimetedByNewLine_ReturnsSum'

● compose test and it's assertion

● run StringCalculatorTestRunner

● see test fail
Develop

accept the new line character 'n' as a delimiter

● solve for requirement (eg. replace 'n' with ',')

● run StringCalculatorTestRunner

● see all tests pass
Review Requirement

The calculator's add function should:

● optionally allow for different default delimiters via "//dn"

● example: add("//;n3;5;2n10;1) should return 21
Compose Test

optionally allow for different default delimiters via "//dn"

● add test called 'Add_InputOptionalDelimiter_ReturnSum'

● compose test and it's assertion

● run StringCalculatorTestRunner

● see test fail
Develop

optionally allow for different default delimiters via "//dn"

● solve for requirement

● run StringCalculatorTestRunner

● see all tests pass
Review Requirement

The calculator's add function should:

● throw an exception when passed a negative number

● exception message is "negatives not allowed"

● include negative in message

● if multiple negatives, include them all in message
Compose Test

throw an exception when passed negative number(s)

● add test called
  'Add_InputNegativeNumbers_ThrowsException'

● compose test and it's assertion

● run StringCalculatorTestRunner

● see test fail
Develop

throw an exception when passed negative number(s)

● solve for requirement

● run StringCalculatorTestRunner

● see all tests pass
Review Requirement

The calculator's add function should:

● ignore numbers larger than 1000
Compose Test

ignore numbers larger than 1000

● add test called
  'Add_InputValuesLargerThan1000_ReturnsSumIgnoringLargeNumbers'

● compose test and it's assertion

● run StringCalculatorTestRunner

● see test fail
Develop

ignore numbers larger than 1000

● solve for requirement

● run StringCalculatorTestRunner

● see all tests pass

More Related Content

PDF
PDF
Tdd iPhone For Dummies
PPTX
Legacy Code Kata v3.0
PPTX
Legacy Dependency Kata v2.0
PPTX
Testing in Scala. Adform Research
PDF
JavaFX8 TestFX - CDI
ODP
Unit Testing and Coverage for AngularJS
PDF
Testing in Ballerina Language
Tdd iPhone For Dummies
Legacy Code Kata v3.0
Legacy Dependency Kata v2.0
Testing in Scala. Adform Research
JavaFX8 TestFX - CDI
Unit Testing and Coverage for AngularJS
Testing in Ballerina Language

What's hot (20)

PPTX
Grails plugin development
ODP
Jquery- One slide completing all JQuery
PPTX
Load Testing with k6 framework
PDF
Bot builder v4 HOL
PDF
Gradle in 45min
DOC
New Microsoft Word Document.doc
PDF
Hyper-pragmatic Pure FP testing with distage-testkit
ODP
Introduction to LAVA Workload Scheduler
PDF
ScalaUA - distage: Staged Dependency Injection
PDF
February'16 SDG - Spring'16 new features
PDF
September SDG - Lightning
PDF
AngularJS Unit Test
PDF
Izumi 1.0: Your Next Scala Stack
PPTX
Test Management System (TMS) using JIRA Customization
PDF
Testing in FrontEnd World by Nikita Galkin
PDF
Scala, Functional Programming and Team Productivity
DOC
VHDL coding in Xilinx
PDF
Understanding react hooks
PDF
Angularjs - Unit testing introduction
PDF
Angular Optimization Web Performance Meetup
Grails plugin development
Jquery- One slide completing all JQuery
Load Testing with k6 framework
Bot builder v4 HOL
Gradle in 45min
New Microsoft Word Document.doc
Hyper-pragmatic Pure FP testing with distage-testkit
Introduction to LAVA Workload Scheduler
ScalaUA - distage: Staged Dependency Injection
February'16 SDG - Spring'16 new features
September SDG - Lightning
AngularJS Unit Test
Izumi 1.0: Your Next Scala Stack
Test Management System (TMS) using JIRA Customization
Testing in FrontEnd World by Nikita Galkin
Scala, Functional Programming and Team Productivity
VHDL coding in Xilinx
Understanding react hooks
Angularjs - Unit testing introduction
Angular Optimization Web Performance Meetup
Ad

Viewers also liked (9)

PDF
JavaScript: Patterns, Part 3
PDF
JavaScript: The Good Parts
PDF
Classic Mistakes
PPT
Presentation janice baay
PDF
Clean Code
PPT
Presentation janice baay
PPT
Presentation janice baay
PPT
Presentation janice baay
PDF
Code Kata
JavaScript: Patterns, Part 3
JavaScript: The Good Parts
Classic Mistakes
Presentation janice baay
Clean Code
Presentation janice baay
Presentation janice baay
Presentation janice baay
Code Kata
Ad

Similar to Code Kata: String Calculator in Flex (20)

PDF
Test driven development
PDF
Unit testing with JUnit
PDF
Scala test
PDF
Test Driven Development with JavaFX
PDF
MT_01_unittest_python.pdf
PPTX
Unit testing
PDF
Describe's Full of It's
PDF
Intro to Unit Testing in AngularJS
ODP
Bring the fun back to java
PPTX
Apex Testing and Best Practices
PDF
How to instantiate any view controller for free
PPTX
Testing Spring Applications
PPTX
Pragmatic unittestingwithj unit
PDF
UPC Testing talk 2
PPS
JUnit Presentation
PPS
J unit presentation
PDF
Java Lab Manual
ODP
Presentation Unit Testing process
DOCX
Test Driven Development
DOCX
Selenium my sql and junit user guide
Test driven development
Unit testing with JUnit
Scala test
Test Driven Development with JavaFX
MT_01_unittest_python.pdf
Unit testing
Describe's Full of It's
Intro to Unit Testing in AngularJS
Bring the fun back to java
Apex Testing and Best Practices
How to instantiate any view controller for free
Testing Spring Applications
Pragmatic unittestingwithj unit
UPC Testing talk 2
JUnit Presentation
J unit presentation
Java Lab Manual
Presentation Unit Testing process
Test Driven Development
Selenium my sql and junit user guide

More from Chris Farrell (9)

PDF
iOS: A Broad Overview
PDF
OpenGL ES on Android
PDF
Android security
PDF
Function Points
PDF
Software Development Fundamentals
PDF
JavaScript: Patterns, Part 2
PDF
JavaScript: Patterns, Part 1
PDF
iOS App Dev
PDF
iOS release engineering
iOS: A Broad Overview
OpenGL ES on Android
Android security
Function Points
Software Development Fundamentals
JavaScript: Patterns, Part 2
JavaScript: Patterns, Part 1
iOS App Dev
iOS release engineering

Code Kata: String Calculator in Flex

  • 1. TDD Code Kata 1 StringCalculator
  • 2. Ground Rules ● do not skip ahead ● no man left behind ● we will only get as far as the whole group gets by 12:50 to allow for discussion at the end ● when we're out of time, that's it ● next time, start from beginning again, not where we left off ● if participating, commit and obey the rules ● if observing, please do not assist or distract
  • 3. Review Requirement There should be a StringCalculator application
  • 4. Compose Test there should be a StringCalculator ● Launch FlashBuilder ● Create an application to run unit tests ● Create a new Flex Desktop Project called StringCalculatorTestRunner in your kata directory ● Add the FlexUnit swc's to to libs ● Add a class named Suite to a package named 'suite' ● Add a class named Test to a package named 'test'
  • 5. Compose Test there should be a StringCalculator ● add flexui:TestRunnerBase component to the test application ● add creationComplete handler to instantiate, init & run FlexUnitCore <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:flexui="org.flexunit.flexui.*" width="1200" height="900" creationComplete="application1_creationCompleteHandler(event)"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; import org.flexunit.runner.FlexUnitCore; import suite.Suite; protected function application1_creationCompleteHandler(event:FlexEvent):void{ var core:FlexUnitCore = new FlexUnitCore(); core.addListener(myRunnerBase); core.run(suite.Suite); } ]]> </fx:Script> <flexui:TestRunnerBase id="myRunnerBase" /> </s:WindowedApplication>
  • 6. Compose Test there should be a StringCalculator ● Edit the Suite class package suite{ import tests.Test; [Suite] [RunWith("org.flexunit.runners.Suite")] public class Suite{ public var test:Test; } }
  • 7. Compose Test there should be a StringCalculator ● Edit the Test class: add a passing test to get started package tests{ import org.flexunit.Assert; public class Test{ [Test] public function Run_App_CompilesWithoutError():void{ var expected:Number = 3; var actual:Number = Math.round(3.4999999); Assert.assertEquals(expected, actual); } } }
  • 8. Develop there should be a StringCalculator ● Create a directory on your computer for this kata project: kata/StringCalculator ● Create a new ActionScript web project called StringCalculator in your directory with default settings ● In Test App's Project Properties>Build Path>Source Path, add your StringCalculator project's src directory ● Run the test app, resolve any compiler issues ● See starter test pass
  • 9. Review Requirement StringCalculator should have an add() function that: ● returns a Number ● accepts a String ● returns 0 for an empty string
  • 10. Compose Test add() should exist and return 0 for empty string ● add a test called 'Add_InputEmptyString_ReturnsZero' ● instantiate the StringCalculator class ● call StringCalculator.add() ● Command+1 to 'create method add' ● run StringCalculatorTestRunner ● see test fail
  • 11. Develop add() should exist and return 0 for empty string ● add a String parameter: add(numbers:String) ● add a return type of Number: add():Number ● add statements: var sum:Number; return sum;
  • 12. Compose Test add() should exist and return 0 for empty string ● assert that 0 is returned for an empty string ● run StringCalclatorTestRunner ● see test fail
  • 13. Develop add() should exist and return 0 for empty string ● add a condition where empty string returns 0 ● run StringCalclatorTestRunner ● see test pass Congratulations! Your first requirement is formally specified Your application's intent is formally documented Your application works as expected
  • 14. Review Requirement The calculator's add function should: ● throw exception for more than 2 inputs ● return the value of 1 valid input ● return the sum of 2 valid inputs
  • 15. Compose Test throw exception for more than 2 inputs ● move StringCalculator to class and create in [Before] ● add test called 'Add_InputMoreThanTwoValues_ThrowsError' ● compose the test and it's assertion ● run StringCalclatorTestRunner ● see test fail
  • 16. Develop throw exception for more than 2 inputs ● add a condition where too many inputs throws an error ● run StringCalclatorTestRunner ● see all tests pass
  • 17. Compose Test return the value of 1 valid input ● add test called 'Add_InputSingleValue_ReturnsInputValue' ● compose the test and it's assertion ● run StringCalclatorTestRunner ● see test fail
  • 18. Develop return the value of 1 valid input ● add condition where single input value is returned ● run StringCalclatorTestRunner ● see all tests pass
  • 19. Compose Test return the sum of 2 valid inputs ● add test called 'Add_InputTwoValues_ReturnsSum' ● compose the test and it's assertion ● run StringCalclatorTestRunner ● see test fail
  • 20. Develop return the sum of 2 valid inputs ● add condition where sum of two inputs is returned ● run StringCalclatorTestRunner ● see all tests pass
  • 21. Review Requirement The calculator's add function should return the sum of any number of inputs Here is a great example of how requirements change on us UnitTests help us to refactor code, safely and with confidence
  • 22. Compose Test return the sum of any number of inputs ● [Ignore] 'Add_InputMoreThanTwoValues_ThrowsError' ● add test called 'Add_InputMoreThanTwoValues_ReturnsSum' ● compose the test and it's assertion ● run StringCalclatorTestRunner ● see test fail
  • 23. Develop return the sum of any number of inputs ● remove condition where more than two inputs throws an error ● add condition and logic to add any number of inputs ● run StringCalclatorTestRunner ● see all tests pass
  • 24. Review Requirement The calculator's add function should: ● accept the new line character 'n' as a delimeter ● 'n' and ',' are allowed in the same input: add('1n2,3')
  • 25. Compose Test accept the new line character 'n' as a delimiter ● add test called 'Add_InputsDelimetedByNewLine_ReturnsSum' ● compose test and it's assertion ● run StringCalculatorTestRunner ● see test fail
  • 26. Develop accept the new line character 'n' as a delimiter ● solve for requirement (eg. replace 'n' with ',') ● run StringCalculatorTestRunner ● see all tests pass
  • 27. Review Requirement The calculator's add function should: ● optionally allow for different default delimiters via "//dn" ● example: add("//;n3;5;2n10;1) should return 21
  • 28. Compose Test optionally allow for different default delimiters via "//dn" ● add test called 'Add_InputOptionalDelimiter_ReturnSum' ● compose test and it's assertion ● run StringCalculatorTestRunner ● see test fail
  • 29. Develop optionally allow for different default delimiters via "//dn" ● solve for requirement ● run StringCalculatorTestRunner ● see all tests pass
  • 30. Review Requirement The calculator's add function should: ● throw an exception when passed a negative number ● exception message is "negatives not allowed" ● include negative in message ● if multiple negatives, include them all in message
  • 31. Compose Test throw an exception when passed negative number(s) ● add test called 'Add_InputNegativeNumbers_ThrowsException' ● compose test and it's assertion ● run StringCalculatorTestRunner ● see test fail
  • 32. Develop throw an exception when passed negative number(s) ● solve for requirement ● run StringCalculatorTestRunner ● see all tests pass
  • 33. Review Requirement The calculator's add function should: ● ignore numbers larger than 1000
  • 34. Compose Test ignore numbers larger than 1000 ● add test called 'Add_InputValuesLargerThan1000_ReturnsSumIgnoringLargeNumbers' ● compose test and it's assertion ● run StringCalculatorTestRunner ● see test fail
  • 35. Develop ignore numbers larger than 1000 ● solve for requirement ● run StringCalculatorTestRunner ● see all tests pass