SlideShare a Scribd company logo
An Introduction To Software
Development Using Python
Spring Semester, 2014
Class #16:
Test Driven
Development
New Idea: Test First, Not Last!
• Don’t try to go back and work testing into a
completed project.
• Instead, build support for testing into the project
from the start.
• New idea: Test Driven Design (TDD) – create code
with testing in mind from the start.
Pay with
Visa
Pay with
MC
Pay with
Paypal
3
3
5
Pay with Visa / MC / Paypal
Test First…
• The “Pay With Visa / Mastercard / PayPal” user story
is going to be broken into tasks.
• If we are going to test first, then we need to look at
our first task
• If we jump right into creating code, then we’ll be
right back where we’ve been doing testing last.
Pay with
Visa
Pay with
MC
Pay with
Paypal
3
3
5
Pay with Visa / MC / Paypal
Analyze The Task
• First we have to break this task down. For this task
we’ll have to:
– Represent the Order Information: We’ll have to capture
the customer’s name, what they are ordering, and the cost
– Represent the Credit Card Information: We’ll need the
credit card info, and their secret card number.
– Represent Receipt Information: We’ll have to capture the
confirmation number, the final cost, as well as the date of
the transaction.
Pay with
Visa
3
Create The Test First!
• Write a test case first!
• Start with the order information part of the
task.
• Use your test framework to create a test for
the “Pay with Visa” functionality.
Image Credit: www.canstockphoto.com
Welcome To TDD!
• When you are creating test cases before you write code and
then letting those test cases drive how you create your code,
you are using Test Driven Development (TDD).
• TDD is a formal term that is used to describe the process of
testing from the outset of development.
• This means that you write every line of code specifically as a
response to your tests.
Image Credit: revistanautilus.ro
How To Write A Test Case
• Your first step needs to be to determine just exactly
what needs to be tested.
• Since this is fine grained testing, testing at the unit
testing level, you should start with a small test.
• Determine what the smallest test that you could
write would be that uses the order information that
you’ll be storing as a part of the first task?
Image Credit: antoni.w-w.pl
Test Case Creation Secrets
• You have no code! You are writing your tests
first.
• There is no way that this test should pass the
first time that you run it.
• The test probably won’t even compile.
However, that’s ok…
• Remember, at first your test case…fails
miserably.
Image Credit: www.clipartpanda.com
TDD Rule #1
• TDD Rule #1: Your test should always fail before you
implement any code.
• You want your tests to fail when you first write them.
• The point of the test is to establish a measurable
success.
• Because your test is failing, now it’s clear what you
have to do to make sure that test passes.
Image Credit: www.fs.usda.gov
Your Next Step…
• Write the simplest code just to get this test to pass.
• This is called “… getting your tests to green.”
• Green refers to a green bar that many automated test case
runners display when all tests pass. If any test fails, a red bar is
displayed.
• TDD Rule #2: Implement the simplest code possible to make
your test cases pass.
Image Credit: www.clipartpanda.com
The YAGNI Principal
• Test-Driven Development is about doing the simplest thing
that you can do in order to get your test case to pass.
• Do not add anything that you MIGHT NEED in the future.
• If you do need something in the future, you’ll write a test case
for it and then you’ll write code to pass that test case.
• Focusing on small bits of code is the key to test-driven
development.
• YAGNI: “Ya ain’t going to need it”
Image Credit: www.fotosearch.com
3 Steps To Test Driven Development
• Red: Your Test Fails
– Write a test to check whatever functionality you are going to write.
– It will fail because you have not yet implemented that functionality.
– This is the red stage because your testing GUI will show the test in red (failing).
• Green: Your Test Passes
– Implement the functionality to get that test to pass
– Write the simplest code possible to get the test to pass.
– This is the green stage.
• Refactor: Clean up – duplication, ugly code, old code, etc.
– After your test passes, go back in and clean up things that you noticed while
implementing your code.
– This is the refactor stage.
– Next, go on to create the next test.
Pay with
Visa
3
Pay with Visa / MC / Paypal
Image Credit: cliparts.co
Exercise: Pay With Visa
• Represent the Order Information: We’ll have to capture the
customer’s name, what they are ordering, and the cost
– What tests can we create for the order
information task?
– What will be the minimal amount of code that we
can implement to pass these tests?
Image Credit: presstigeprinting.com
In TDD, Tests Drive Your
Implementation
• TDD drives your implementation all the way through
development.
• By writing tests before code, you have to focus on
the functionality right off the bat.
• What is the code that you are creating supposed to
do?
Image Credit: www.clipartpanda.com
Good TDD Habits
• Each test should verify only one thing
– Make each test only test one thing
• Avoid duplicate test code
– Just like you avoid duplicate code, avoid duplicate tests.
• Keep your tests in a mirror directory of your source code
– You will be creating a lot of test cases
– Keep your tests in a separate subdirectory on the same level as your
source code and with the same directory structure.
– This will make life easier for your build scripts
Image Credit: www.dreamstime.com
Completing A Task
• You’ve got all the tests that you need and they all
pass.
• When your tests pass, move on!
• Different task, use the same process…
Image Credit: cliparts.co
Dependencies Are A Bad Thing
When It Comes To Testing
• Simple code means that you can break things up
and test parts of your code one thing at a time.
• Dependencies: code that depends on something
that is external to your code (like a database or an
interface)
• Dependencies make it hard to test one thing at a
time
• Your job is to figure out a way to test your code
independent of the dependencies
Image Credit: blogs.msdn.com
First You Have To Find Your
DependenciesPay with
Visa
3
– Represent the Order Information:
• Get card owner’s name
• Get card owner’s address
– Represent the Credit Card
Information:
• Get credit card number
• Get secret confirmation number
– Represent Receipt Information:
• Provide confirmation number
• The final cost
• Date of the transaction.
Name
Address
CC #
Secret #
CC #
Secret #
Conf #
Cost
Date
Conf #
Cost
Date
Your
Program
Your
Program
Your
Program
Credit
Card
Paper
Need To Create Testing Interfaces
Name
Address
CC #
Secret #
Dummy
Input
Conf #
Cost
Date
Dummy
Output
Your
Program
Your
Program
Your
Program
• Need to hide how our application gets and
gives its data
• Change how this works depending on if we
are conducting testing or running in
production
• We want to have two different ways of
passing the information that we want
• Our program does not have to know which
one it is using
Dummy
Input
Code
Stub
Code
Stub
Image Credit: www.clker.com
What Would This Look Like
In Python?
#
# Constants used in this program
runningTest = 1 # 0 = in production, 1 = testing being done
#
# Collect personal information from credit card owner
if (runningTest == 0) :
lastName = input("Please enter last name: ")
firstName = input("Please enter first name: ")
middleInitial = input("Please enter the middle initial: ")
streetAddress = input("Please enter street address: ")
city = input("Please enter city: ")
state = input("Please enter state: ")
zip = input("Please enter zip: ")
else:
lastName = "Johnson"
firstName = "Fred“
middleInitial = "N"
streetAddress = “2763 Filibuster Drive”
city = "Lakeland"
state = “FL”
zip = "37643"
Image Credit: 4vector.com
What Does Testing First Buy Us?
• Testing produces better code
• Create well-organized code
– Simpler code
– Nothing that is not absolutely required
• Code that always does the same thing
– Production code does the same thing as testing code
– We are writing production code all the time
• Code is loosely coupled
– Tightly coupled code is brittle and breaks easily
– Our code will be broken into a loosely coupled flexible system
Image Credit: www.fotosearch.com
What Kind Of Tests Do We Have To
Write Now?
Name
Address
CC #
Secret #
CC #
Secret #
Conf #
Cost
Date
Conf #
Cost
Date
Your
Program
Your
Program
Your
Program
Credit
Card
Paper
Name too long
Name too short
Illegal name characters
Street too long
Street too short
Illegal street characters
No name
No street
No CC #
CC # too long
CC # too short
No secret #
Secret # too long
Secret # too short
Wrong secret #
Valid name
Valid street
Valid CC #
Valid secret #
Valid conf #
Valid cost
Valid date
22
Tests
Things NOT To Do When
Writing Code
Testing Nothing:
You can write a lot of test code that doesn’t really
test anything. Could place a credit card order and
then not test the cost printed on the final receipt.
Don’t Test Your Data:
It can be all too easy to create test cases that test
the fake data that you’ve created and not the code
that you’ve written.
Get Rid Of Scraps:
The system state that your testing starts in is very
important. You need to always clean up and start
in the same state each time.
Image Credit: alexrister1.wordpress.com
So Just Exactly What Have We
Learned About Testing?
1. Always write the test before you write the code.
2. Make the test fail first, then write the
simplest code that will make the test pass
3. Each test should only test one thing
4. Once your tests pass, you can then clean
up your code (refactor)
5. When you are out of tests to write, you’re done!
Image Credit: clipart-finder.com
What We Covered Today
1. Test first, not last!
2. Test-Driven Development
3. TDD Rule #1: Your test
should always fail before
you implement any code.
4. TDD Rule #2: Implement
the simplest code possible
to make your test cases
pass.
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
What We’ll Be Covering Next Time
1. Ending an iteration
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

More Related Content

PPTX
An Introduction To Software Development - Test Driven Development, Part 1
PDF
Adopting tdd in the workplace
PPTX
Cucumber From the Ground Up - Joseph Beale
PDF
Inside Behavior Driven Development
PDF
YAGNI Principle and Clean Code
PDF
TDD — Are you sure you properly test code?
PDF
WE are Doing it Wrong - Dmitry Sharkov
PDF
Adapting Agility: Getting your Agile Transformation Unstuck
An Introduction To Software Development - Test Driven Development, Part 1
Adopting tdd in the workplace
Cucumber From the Ground Up - Joseph Beale
Inside Behavior Driven Development
YAGNI Principle and Clean Code
TDD — Are you sure you properly test code?
WE are Doing it Wrong - Dmitry Sharkov
Adapting Agility: Getting your Agile Transformation Unstuck

What's hot (12)

PPTX
The Art of Gherkin Scripting - Matt Eakin
PDF
Best Practices in Software Development
PDF
Lessons learned with Bdd: a tutorial
PPTX
BDD Primer
PDF
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
PDF
Growing Manual Testers into Automators
PPTX
Clean Code
PDF
Inside Requirements
PDF
Prefer Code to Comments
PPTX
Clean code coding like a professional
PDF
PDF
Adopting technical practices 2013
The Art of Gherkin Scripting - Matt Eakin
Best Practices in Software Development
Lessons learned with Bdd: a tutorial
BDD Primer
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
Growing Manual Testers into Automators
Clean Code
Inside Requirements
Prefer Code to Comments
Clean code coding like a professional
Adopting technical practices 2013
Ad

Viewers also liked (13)

PPTX
An Introduction To Python - Modules & Solving Real World Problems
PPTX
An Introduction To Python - Tables, List Algorithms
PPTX
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
PPTX
Intro To C++ - Class 10 - Control Statements: Part 2
PPTX
An Introduction To Python - Understanding Computers
PPTX
An Introduction To Python - Python, Print()
PPTX
Intro To C++ - Class 14 - Midterm Review
PPTX
Cloud Computing: How to Change The World In 1,825 Days…
PPTX
An Introduction To Software Development - Design Strategies
PPTX
An Introduction To Software Development - Implementation
PPTX
An Introduction To Python - Working With Data
PPTX
Intro To C++ - Class 11 - Converting between types, formatting floating point...
PPTX
Using A Balanced Scorecard For An IT Department -- The Secret To Knowing Wher...
An Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Tables, List Algorithms
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 10 - Control Statements: Part 2
An Introduction To Python - Understanding Computers
An Introduction To Python - Python, Print()
Intro To C++ - Class 14 - Midterm Review
Cloud Computing: How to Change The World In 1,825 Days…
An Introduction To Software Development - Design Strategies
An Introduction To Software Development - Implementation
An Introduction To Python - Working With Data
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Using A Balanced Scorecard For An IT Department -- The Secret To Knowing Wher...
Ad

Similar to An Introduction To Software Development - Test Driven Development (20)

PDF
An Introduction To Software Development - Final Review
PPTX
Unit testing
PDF
Adopting tdd in the workplace
PPTX
{10.0} Test Driven Development.pptx
PPTX
A Brief Introduction to Test-Driven Development
PPTX
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
PPTX
Gateway to Agile: XP and BDD
PPT
Test Driven Development and Automation
PPT
Chapter 6,7 Software coding and Testing.ppt
PPTX
Test Driven Development on Android (Kotlin Kenya)
PDF
The Cowardly Test-o-Phobe's Guide To Testing
PDF
What CS Class Didn't Teach About Testing
PDF
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
PPTX
TDD: seriously, try it! 
KEY
Driving application development through behavior driven development
PPTX
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
PPTX
An Introduction To Software Development - Testing, Continuous integration
PPTX
Finding a good development partner
PPT
TDD_demo.ppt
An Introduction To Software Development - Final Review
Unit testing
Adopting tdd in the workplace
{10.0} Test Driven Development.pptx
A Brief Introduction to Test-Driven Development
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
Gateway to Agile: XP and BDD
Test Driven Development and Automation
Chapter 6,7 Software coding and Testing.ppt
Test Driven Development on Android (Kotlin Kenya)
The Cowardly Test-o-Phobe's Guide To Testing
What CS Class Didn't Teach About Testing
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
TDD: seriously, try it! 
Driving application development through behavior driven development
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
An Introduction To Software Development - Testing, Continuous integration
Finding a good development partner
TDD_demo.ppt

Recently uploaded (20)

PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Institutional Correction lecture only . . .
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Classroom Observation Tools for Teachers
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Presentation on HIE in infants and its manifestations
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Module 4: Burden of Disease Tutorial Slides S2 2025
Institutional Correction lecture only . . .
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Classroom Observation Tools for Teachers
102 student loan defaulters named and shamed – Is someone you know on the list?
Presentation on HIE in infants and its manifestations
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
STATICS OF THE RIGID BODIES Hibbelers.pdf
GDM (1) (1).pptx small presentation for students
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
A systematic review of self-coping strategies used by university students to ...
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Final Presentation General Medicine 03-08-2024.pptx
O7-L3 Supply Chain Operations - ICLT Program

An Introduction To Software Development - Test Driven Development

  • 1. An Introduction To Software Development Using Python Spring Semester, 2014 Class #16: Test Driven Development
  • 2. New Idea: Test First, Not Last! • Don’t try to go back and work testing into a completed project. • Instead, build support for testing into the project from the start. • New idea: Test Driven Design (TDD) – create code with testing in mind from the start. Pay with Visa Pay with MC Pay with Paypal 3 3 5 Pay with Visa / MC / Paypal
  • 3. Test First… • The “Pay With Visa / Mastercard / PayPal” user story is going to be broken into tasks. • If we are going to test first, then we need to look at our first task • If we jump right into creating code, then we’ll be right back where we’ve been doing testing last. Pay with Visa Pay with MC Pay with Paypal 3 3 5 Pay with Visa / MC / Paypal
  • 4. Analyze The Task • First we have to break this task down. For this task we’ll have to: – Represent the Order Information: We’ll have to capture the customer’s name, what they are ordering, and the cost – Represent the Credit Card Information: We’ll need the credit card info, and their secret card number. – Represent Receipt Information: We’ll have to capture the confirmation number, the final cost, as well as the date of the transaction. Pay with Visa 3
  • 5. Create The Test First! • Write a test case first! • Start with the order information part of the task. • Use your test framework to create a test for the “Pay with Visa” functionality. Image Credit: www.canstockphoto.com
  • 6. Welcome To TDD! • When you are creating test cases before you write code and then letting those test cases drive how you create your code, you are using Test Driven Development (TDD). • TDD is a formal term that is used to describe the process of testing from the outset of development. • This means that you write every line of code specifically as a response to your tests. Image Credit: revistanautilus.ro
  • 7. How To Write A Test Case • Your first step needs to be to determine just exactly what needs to be tested. • Since this is fine grained testing, testing at the unit testing level, you should start with a small test. • Determine what the smallest test that you could write would be that uses the order information that you’ll be storing as a part of the first task? Image Credit: antoni.w-w.pl
  • 8. Test Case Creation Secrets • You have no code! You are writing your tests first. • There is no way that this test should pass the first time that you run it. • The test probably won’t even compile. However, that’s ok… • Remember, at first your test case…fails miserably. Image Credit: www.clipartpanda.com
  • 9. TDD Rule #1 • TDD Rule #1: Your test should always fail before you implement any code. • You want your tests to fail when you first write them. • The point of the test is to establish a measurable success. • Because your test is failing, now it’s clear what you have to do to make sure that test passes. Image Credit: www.fs.usda.gov
  • 10. Your Next Step… • Write the simplest code just to get this test to pass. • This is called “… getting your tests to green.” • Green refers to a green bar that many automated test case runners display when all tests pass. If any test fails, a red bar is displayed. • TDD Rule #2: Implement the simplest code possible to make your test cases pass. Image Credit: www.clipartpanda.com
  • 11. The YAGNI Principal • Test-Driven Development is about doing the simplest thing that you can do in order to get your test case to pass. • Do not add anything that you MIGHT NEED in the future. • If you do need something in the future, you’ll write a test case for it and then you’ll write code to pass that test case. • Focusing on small bits of code is the key to test-driven development. • YAGNI: “Ya ain’t going to need it” Image Credit: www.fotosearch.com
  • 12. 3 Steps To Test Driven Development • Red: Your Test Fails – Write a test to check whatever functionality you are going to write. – It will fail because you have not yet implemented that functionality. – This is the red stage because your testing GUI will show the test in red (failing). • Green: Your Test Passes – Implement the functionality to get that test to pass – Write the simplest code possible to get the test to pass. – This is the green stage. • Refactor: Clean up – duplication, ugly code, old code, etc. – After your test passes, go back in and clean up things that you noticed while implementing your code. – This is the refactor stage. – Next, go on to create the next test. Pay with Visa 3 Pay with Visa / MC / Paypal Image Credit: cliparts.co
  • 13. Exercise: Pay With Visa • Represent the Order Information: We’ll have to capture the customer’s name, what they are ordering, and the cost – What tests can we create for the order information task? – What will be the minimal amount of code that we can implement to pass these tests? Image Credit: presstigeprinting.com
  • 14. In TDD, Tests Drive Your Implementation • TDD drives your implementation all the way through development. • By writing tests before code, you have to focus on the functionality right off the bat. • What is the code that you are creating supposed to do? Image Credit: www.clipartpanda.com
  • 15. Good TDD Habits • Each test should verify only one thing – Make each test only test one thing • Avoid duplicate test code – Just like you avoid duplicate code, avoid duplicate tests. • Keep your tests in a mirror directory of your source code – You will be creating a lot of test cases – Keep your tests in a separate subdirectory on the same level as your source code and with the same directory structure. – This will make life easier for your build scripts Image Credit: www.dreamstime.com
  • 16. Completing A Task • You’ve got all the tests that you need and they all pass. • When your tests pass, move on! • Different task, use the same process… Image Credit: cliparts.co
  • 17. Dependencies Are A Bad Thing When It Comes To Testing • Simple code means that you can break things up and test parts of your code one thing at a time. • Dependencies: code that depends on something that is external to your code (like a database or an interface) • Dependencies make it hard to test one thing at a time • Your job is to figure out a way to test your code independent of the dependencies Image Credit: blogs.msdn.com
  • 18. First You Have To Find Your DependenciesPay with Visa 3 – Represent the Order Information: • Get card owner’s name • Get card owner’s address – Represent the Credit Card Information: • Get credit card number • Get secret confirmation number – Represent Receipt Information: • Provide confirmation number • The final cost • Date of the transaction. Name Address CC # Secret # CC # Secret # Conf # Cost Date Conf # Cost Date Your Program Your Program Your Program Credit Card Paper
  • 19. Need To Create Testing Interfaces Name Address CC # Secret # Dummy Input Conf # Cost Date Dummy Output Your Program Your Program Your Program • Need to hide how our application gets and gives its data • Change how this works depending on if we are conducting testing or running in production • We want to have two different ways of passing the information that we want • Our program does not have to know which one it is using Dummy Input Code Stub Code Stub Image Credit: www.clker.com
  • 20. What Would This Look Like In Python? # # Constants used in this program runningTest = 1 # 0 = in production, 1 = testing being done # # Collect personal information from credit card owner if (runningTest == 0) : lastName = input("Please enter last name: ") firstName = input("Please enter first name: ") middleInitial = input("Please enter the middle initial: ") streetAddress = input("Please enter street address: ") city = input("Please enter city: ") state = input("Please enter state: ") zip = input("Please enter zip: ") else: lastName = "Johnson" firstName = "Fred“ middleInitial = "N" streetAddress = “2763 Filibuster Drive” city = "Lakeland" state = “FL” zip = "37643" Image Credit: 4vector.com
  • 21. What Does Testing First Buy Us? • Testing produces better code • Create well-organized code – Simpler code – Nothing that is not absolutely required • Code that always does the same thing – Production code does the same thing as testing code – We are writing production code all the time • Code is loosely coupled – Tightly coupled code is brittle and breaks easily – Our code will be broken into a loosely coupled flexible system Image Credit: www.fotosearch.com
  • 22. What Kind Of Tests Do We Have To Write Now? Name Address CC # Secret # CC # Secret # Conf # Cost Date Conf # Cost Date Your Program Your Program Your Program Credit Card Paper Name too long Name too short Illegal name characters Street too long Street too short Illegal street characters No name No street No CC # CC # too long CC # too short No secret # Secret # too long Secret # too short Wrong secret # Valid name Valid street Valid CC # Valid secret # Valid conf # Valid cost Valid date 22 Tests
  • 23. Things NOT To Do When Writing Code Testing Nothing: You can write a lot of test code that doesn’t really test anything. Could place a credit card order and then not test the cost printed on the final receipt. Don’t Test Your Data: It can be all too easy to create test cases that test the fake data that you’ve created and not the code that you’ve written. Get Rid Of Scraps: The system state that your testing starts in is very important. You need to always clean up and start in the same state each time. Image Credit: alexrister1.wordpress.com
  • 24. So Just Exactly What Have We Learned About Testing? 1. Always write the test before you write the code. 2. Make the test fail first, then write the simplest code that will make the test pass 3. Each test should only test one thing 4. Once your tests pass, you can then clean up your code (refactor) 5. When you are out of tests to write, you’re done! Image Credit: clipart-finder.com
  • 25. What We Covered Today 1. Test first, not last! 2. Test-Driven Development 3. TDD Rule #1: Your test should always fail before you implement any code. 4. TDD Rule #2: Implement the simplest code possible to make your test cases pass. Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
  • 26. What We’ll Be Covering Next Time 1. Ending an iteration Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

Editor's Notes

  • #2: New name for the class I know what this means Technical professionals are who get hired This means much more than just having a narrow vertical knowledge of some subject area. It means that you know how to produce an outcome that I value. I’m willing to pay you to do that.