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
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
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
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