TDD workshop
Agenda
- Hello World
- Benefits of TDD
- Code coverage
- Roman Numerals Kata
- Zodiac app
- ETA Detroit app
Hello World

Lab 1 - Hello World
1. Open Xcode
2. Make sure Xcode is 8.x
3. Open Main.storyboard
4. Search for TextView in the Object Library
5. Drag over to Storyboard
6. Run
Lab 2 - Hello World
1. Open Terminal
2. cd /path/to/HelloWorld
3. Run the command
xcodebuild build -project HelloWorld.xcodeproj
-scheme HelloWorld
-destination 'platform=iOS Simulator,name=iPhone 7 Plus'
Test Driven Development

Test Driven Development
- Write test first
- See it fail
- Write simplest possible solution to get test to pass
- Refactor
- Wash, Rinse, Repeat
Uncle Bob's Rules
- You are not allowed to write any production code unless it is to pass a failing unit test
- You are not allowed to write any more of a unit test than is sufficient to fail, and compilation failures are failures
- You are not allowed to write any more production code than is sufficient to pass the one failing unit test
Test Driven Development
- Built in regression testing
- Longer life for your codebase
- YAGNI feature development
- Red/Green/Refactor helps kill procrastination
TDD
You can't TDD w/o unit testing
TDD means writing the tests before the code
TDD is more painless than classic unit testing
Unit Testing
You can unit test w/o TDD
Unit tests don't mandate when you write the tests
Unit tests are often written at the end of a coding cycle
Lab 3 - Hello World TDD
Features
- User gets valid result when
dividing divisor by dividend
- User can not divide by zero

Lab 3 - Hello World TDD
1. Create Xcode project called Division
2. Add two text fields, divide and results label and button
3. Create IBoutlets, IBActions
4. Create Calculator object
5. Create Unit test for feature 1
6. Run test - test will fail
7. Fix Calculator code so test passes
8. Create Unit test for feature 2
9. Run test - test will fail
10. Fix Calculator code so test passes
11. Run test
12. Refactor - fix ViewController code
13. Turn on code coverage
14. View code coverage
XCode TDD

XCode TDD

Exercism Kata

Exercism Kata
Write a function to convert from Arabic numbers to Roman Numerals
Write a function to convert from Roman Numerals to Arabic numbers
Exercism Kata
1. Create ArabicToRoman project in Xcode
2. Check Unit Tests
3. Open ArabicToRomanTests - use the two screens in Xcode
4. Create ArabicToRomanModel.swift
5. Create toRoman stub function
6. Create testConvertToRoman test
7. Run test from command line, test will fail
8. Fix toRoman stub function
9. Run test from command line, test passes
10. Refactor
11. Repeat for second feature
XCode TDD

Sample App
Feature 1 - Display list of Zodiac Signs
Feature 2 - Display descriptions of Sign
Feature 3 - Display daily horoscope
Sample App


Resource
https://medium.com/@ynzc/getting-started-with-tdd-in-swift-2fab3e07204b
https://github.com/samantha-wong/FizzBuzz
https://gist.github.com/kumo/472043819fec7a3737f8
https://github.com/pigmonchu/TDDiOS
http://rshankar.com/test-driven-development-in-swift/
TDD workshop
By godfreynolan
TDD workshop
- 824