SlideShare une entreprise Scribd logo
1  sur  35
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

Contenu connexe

Tendances

Grails plugin development
Grails plugin developmentGrails plugin development
Grails plugin developmentMohd Farid
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQueryKnoldus Inc.
 
Load Testing with k6 framework
Load Testing with k6 frameworkLoad Testing with k6 framework
Load Testing with k6 frameworkSvetlin Nakov
 
New Microsoft Word Document.doc
New Microsoft Word Document.docNew Microsoft Word Document.doc
New Microsoft Word Document.docbutest
 
Hyper-pragmatic Pure FP testing with distage-testkit
Hyper-pragmatic Pure FP testing with distage-testkitHyper-pragmatic Pure FP testing with distage-testkit
Hyper-pragmatic Pure FP testing with distage-testkit7mind
 
Introduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerIntroduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerNopparat Nopkuat
 
ScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency InjectionScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency Injection7mind
 
February'16 SDG - Spring'16 new features
February'16 SDG - Spring'16 new featuresFebruary'16 SDG - Spring'16 new features
February'16 SDG - Spring'16 new featuresJosep Vall-llovera
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit TestChiew Carol
 
Izumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala StackIzumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala Stack7mind
 
Test Management System (TMS) using JIRA Customization
Test Management System (TMS) using JIRA CustomizationTest Management System (TMS) using JIRA Customization
Test Management System (TMS) using JIRA CustomizationYagnanarayana Dande
 
Testing in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinTesting in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinSigma Software
 
Scala, Functional Programming and Team Productivity
Scala, Functional Programming and Team ProductivityScala, Functional Programming and Team Productivity
Scala, Functional Programming and Team Productivity7mind
 
VHDL coding in Xilinx
VHDL coding in XilinxVHDL coding in Xilinx
VHDL coding in XilinxNaveen Kumar
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooksSamundra khatri
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introductionNir Kaufman
 
Angular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupAngular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupDavid Barreto
 

Tendances (20)

Grails plugin development
Grails plugin developmentGrails plugin development
Grails plugin development
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Load Testing with k6 framework
Load Testing with k6 frameworkLoad Testing with k6 framework
Load Testing with k6 framework
 
Bot builder v4 HOL
Bot builder v4 HOLBot builder v4 HOL
Bot builder v4 HOL
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
New Microsoft Word Document.doc
New Microsoft Word Document.docNew Microsoft Word Document.doc
New Microsoft Word Document.doc
 
Hyper-pragmatic Pure FP testing with distage-testkit
Hyper-pragmatic Pure FP testing with distage-testkitHyper-pragmatic Pure FP testing with distage-testkit
Hyper-pragmatic Pure FP testing with distage-testkit
 
Introduction to LAVA Workload Scheduler
Introduction to LAVA Workload SchedulerIntroduction to LAVA Workload Scheduler
Introduction to LAVA Workload Scheduler
 
ScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency InjectionScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency Injection
 
February'16 SDG - Spring'16 new features
February'16 SDG - Spring'16 new featuresFebruary'16 SDG - Spring'16 new features
February'16 SDG - Spring'16 new features
 
September SDG - Lightning
September SDG - LightningSeptember SDG - Lightning
September SDG - Lightning
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Izumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala StackIzumi 1.0: Your Next Scala Stack
Izumi 1.0: Your Next Scala Stack
 
Test Management System (TMS) using JIRA Customization
Test Management System (TMS) using JIRA CustomizationTest Management System (TMS) using JIRA Customization
Test Management System (TMS) using JIRA Customization
 
Testing in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinTesting in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita Galkin
 
Scala, Functional Programming and Team Productivity
Scala, Functional Programming and Team ProductivityScala, Functional Programming and Team Productivity
Scala, Functional Programming and Team Productivity
 
VHDL coding in Xilinx
VHDL coding in XilinxVHDL coding in Xilinx
VHDL coding in Xilinx
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 
Angular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupAngular Optimization Web Performance Meetup
Angular Optimization Web Performance Meetup
 

En vedette

JavaScript: Patterns, Part 3
JavaScript: Patterns, Part  3JavaScript: Patterns, Part  3
JavaScript: Patterns, Part 3Chris Farrell
 
JavaScript: The Good Parts
JavaScript: The Good PartsJavaScript: The Good Parts
JavaScript: The Good PartsChris Farrell
 
Presentation janice baay
Presentation janice baayPresentation janice baay
Presentation janice baayJanice Baay
 
Presentation janice baay
Presentation janice baayPresentation janice baay
Presentation janice baayJanice Baay
 
Presentation janice baay
Presentation janice baayPresentation janice baay
Presentation janice baayJanice Baay
 
Presentation janice baay
Presentation janice baayPresentation janice baay
Presentation janice baayJanice Baay
 

En vedette (9)

JavaScript: Patterns, Part 3
JavaScript: Patterns, Part  3JavaScript: Patterns, Part  3
JavaScript: Patterns, Part 3
 
JavaScript: The Good Parts
JavaScript: The Good PartsJavaScript: The Good Parts
JavaScript: The Good Parts
 
Classic Mistakes
Classic MistakesClassic Mistakes
Classic Mistakes
 
Presentation janice baay
Presentation janice baayPresentation janice baay
Presentation janice baay
 
Clean Code
Clean CodeClean Code
Clean Code
 
Presentation janice baay
Presentation janice baayPresentation janice baay
Presentation janice baay
 
Presentation janice baay
Presentation janice baayPresentation janice baay
Presentation janice baay
 
Presentation janice baay
Presentation janice baayPresentation janice baay
Presentation janice baay
 
Code Kata
Code KataCode Kata
Code Kata
 

Similaire à Code Kata: String Calculator in Flex

Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdfHans Jones
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It'sJim Lynch
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSJim Lynch
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best PracticesJitendra Zaa
 
How to instantiate any view controller for free
How to instantiate any view controller for freeHow to instantiate any view controller for free
How to instantiate any view controller for freeBenotCaron
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unitliminescence
 
J unit presentation
J unit presentationJ unit presentation
J unit presentationPriya Sharma
 
Selenium my sql and junit user guide
Selenium my sql and junit user guideSelenium my sql and junit user guide
Selenium my sql and junit user guideFahad Shiekh
 

Similaire à Code Kata: String Calculator in Flex (20)

Test driven development
Test driven developmentTest driven development
Test driven development
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Scala test
Scala testScala test
Scala test
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Unit testing
Unit testingUnit testing
Unit testing
 
Describe's Full of It's
Describe's Full of It'sDescribe's Full of It's
Describe's Full of It's
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best Practices
 
How to instantiate any view controller for free
How to instantiate any view controller for freeHow to instantiate any view controller for free
How to instantiate any view controller for free
 
Testing Spring Applications
Testing Spring ApplicationsTesting Spring Applications
Testing Spring Applications
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
 
UPC Testing talk 2
UPC Testing talk 2UPC Testing talk 2
UPC Testing talk 2
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Presentation Unit Testing process
Presentation Unit Testing processPresentation Unit Testing process
Presentation Unit Testing process
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Selenium my sql and junit user guide
Selenium my sql and junit user guideSelenium my sql and junit user guide
Selenium my sql and junit user guide
 

Plus de Chris Farrell

iOS: A Broad Overview
iOS: A Broad OverviewiOS: A Broad Overview
iOS: A Broad OverviewChris Farrell
 
OpenGL ES on Android
OpenGL ES on AndroidOpenGL ES on Android
OpenGL ES on AndroidChris Farrell
 
Software Development Fundamentals
Software Development FundamentalsSoftware Development Fundamentals
Software Development FundamentalsChris Farrell
 
JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2Chris Farrell
 
JavaScript: Patterns, Part 1
JavaScript: Patterns, Part  1JavaScript: Patterns, Part  1
JavaScript: Patterns, Part 1Chris Farrell
 
iOS release engineering
iOS release engineeringiOS release engineering
iOS release engineeringChris Farrell
 

Plus de Chris Farrell (9)

iOS: A Broad Overview
iOS: A Broad OverviewiOS: A Broad Overview
iOS: A Broad Overview
 
OpenGL ES on Android
OpenGL ES on AndroidOpenGL ES on Android
OpenGL ES on Android
 
Android security
Android securityAndroid security
Android security
 
Function Points
Function PointsFunction Points
Function Points
 
Software Development Fundamentals
Software Development FundamentalsSoftware Development Fundamentals
Software Development Fundamentals
 
JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2
 
JavaScript: Patterns, Part 1
JavaScript: Patterns, Part  1JavaScript: Patterns, Part  1
JavaScript: Patterns, Part 1
 
iOS App Dev
iOS App Dev iOS App Dev
iOS App Dev
 
iOS release engineering
iOS release engineeringiOS release engineering
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