SlideShare ist ein Scribd-Unternehmen logo
1 von 25
An Introduction To Software
Development Using Python
Spring Semester, 2014
Class #13:
Test Driven
Development, Part 1
3 Different Types Of Testing
• Unit Testing
– Performed by developers
– Goal is to ensure that their code works correctly
• System Testing
– Performed by professional testers
– Goal is to ensure that the parts work together
• User Testing
– Performed by professional testers
– Goal is to ensure that the expected functions work
Image Credit www.fotosearch.com
Python Has Two Testing Tools
unittest
• Automated testing framework
• Python’s unittest module, sometimes
referred to as PyUnit, is based on the
XUnit framework design by Kent Beck
and Erich Gamma.
• The same pattern is repeated in many
other languages, including C, perl,
Java, and Smalltalk.
• The framework implemented by
unittest supports fixtures, test suites,
and a test runner to enable
automated testing for your code.
Py.test
• A mature full-featured Python testing
tool
• Provides easy no-boilerplate testing
• Scales from simple unit to complex
functional testing
• Integrates with other testing
methods and tools:
• Extensive plugin and customization
system:
What Would A Py.Test Script Look
Like For Homework #1?
#
# Encrypt the social security number
encryptedSS = ""
encryptedSS += socialSecurityNum[10]
encryptedSS += socialSecurityNum[9]
encryptedSS += socialSecurityNum[8]
encryptedSS += socialSecurityNum[7]
encryptedSS += socialSecurityNum[6]
encryptedSS += socialSecurityNum[5]
encryptedSS += socialSecurityNum[4]
encryptedSS += socialSecurityNum[3]
encryptedSS += socialSecurityNum[2]
encryptedSS += socialSecurityNum[1]
encryptedSS += socialSecurityNum[0]
def test_encrypted_SS ():
assert encryptedSS == ‘6270-55-461’
Image Credit www.objective.no
What Is Continuous Integration?
• Version control keeps track of our code
• Now we have automated tests
• We need to tie these two things together
• Continuous Integration tools do the following:
– Compile code
– Run the automated tests
– Display and mail out reports when new code is committed
to the repository
Image Credit www.guruintechnocrats.com
Continuous Integration In Action
Bob
1. Bob checks code into
the server
2. Version control code
notifies continuous
integration tool that there
is new code
3. Continuous integration tool
checks out the new code, compiles
it and runs all of your tests on it.
Most build tools also create a
web page and email the team to
let them know how things are
going.
How Many Tests Do You Need?
• Trade off: how much of the code that you test vs. the
chances of finding a bug in the part that you haven’t
tested.
• Testing the same code several different ways won’t
do you much good.
• Don’t focus on the number of tests you have, instead
focus on the coverage of your tests: % of code tested.
• Most projects aim for 85% - 90% coverage
Image Credit www.clker.com
What If…?
• Good software needs to work.
• How do you know that your software works?
• Even with unit testing, there is the possibility that a portion of
your code is untested.
• What if testing was a fundamental part of your software
development process?
• What if everything was done with testing in mind?
• Version Control + Continuous Integration + Automated Testing
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.
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.
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?
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.
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.
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.
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”
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
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?
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
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…
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. Test driven
development, Part 2
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

Weitere ähnliche Inhalte

Was ist angesagt?

Code Review
Code ReviewCode Review
Code ReviewTu Hoang
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...AgileNetwork
 
TDD — Are you sure you properly test code?
TDD — Are you sure you properly test code?TDD — Are you sure you properly test code?
TDD — Are you sure you properly test code?Dmitriy Nesteryuk
 
Test scenarios for sending & receiving emails
Test scenarios for sending & receiving emailsTest scenarios for sending & receiving emails
Test scenarios for sending & receiving emailsMorpheous Algan
 
Code Review
Code ReviewCode Review
Code ReviewDivante
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Søren Lund
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit TestingSøren Lund
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and WhenPaul Gower
 
Code Review
Code ReviewCode Review
Code Reviewrantav
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016Søren Lund
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplaceDonny Wals
 
Code review
Code reviewCode review
Code reviewdqpi
 
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven DevelopmentABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven DevelopmentHendrik Neumann
 
Code review guidelines
Code review guidelinesCode review guidelines
Code review guidelinesLalit Kale
 
Code Review
Code ReviewCode Review
Code ReviewRavi Raj
 
Lessons Learned in Test Automation From Zombieland
Lessons Learned in Test Automation From ZombielandLessons Learned in Test Automation From Zombieland
Lessons Learned in Test Automation From ZombielandMatt Barbour
 

Was ist angesagt? (18)

Code Review
Code ReviewCode Review
Code Review
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
TDD — Are you sure you properly test code?
TDD — Are you sure you properly test code?TDD — Are you sure you properly test code?
TDD — Are you sure you properly test code?
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Test scenarios for sending & receiving emails
Test scenarios for sending & receiving emailsTest scenarios for sending & receiving emails
Test scenarios for sending & receiving emails
 
Code Review
Code ReviewCode Review
Code Review
 
Code Review
Code ReviewCode Review
Code Review
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit Testing
 
Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
 
Code Review
Code ReviewCode Review
Code Review
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
Code review
Code reviewCode review
Code review
 
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven DevelopmentABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
ABAP Code Retreat Frankfurt 2016: TDD - Test Driven Development
 
Code review guidelines
Code review guidelinesCode review guidelines
Code review guidelines
 
Code Review
Code ReviewCode Review
Code Review
 
Lessons Learned in Test Automation From Zombieland
Lessons Learned in Test Automation From ZombielandLessons Learned in Test Automation From Zombieland
Lessons Learned in Test Automation From Zombieland
 

Andere mochten auch

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentnikhil sreeni
 
Software architecture...Yes, on tests!
Software architecture...Yes, on tests!Software architecture...Yes, on tests!
Software architecture...Yes, on tests!Codemotion
 
London SDET Meetup (April 2016) - M&S Digital Test Journey
London SDET Meetup (April 2016) - M&S Digital Test JourneyLondon SDET Meetup (April 2016) - M&S Digital Test Journey
London SDET Meetup (April 2016) - M&S Digital Test JourneyRichard Chernanko
 
Pratap Kumar Nallamothu SDET2
Pratap Kumar Nallamothu SDET2Pratap Kumar Nallamothu SDET2
Pratap Kumar Nallamothu SDET2pratap kumar
 
Testing without Testers
Testing without TestersTesting without Testers
Testing without TestersAlan Page
 
Appium & Robot Framework
Appium & Robot FrameworkAppium & Robot Framework
Appium & Robot FrameworkFurkan Ertürk
 
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...agil8 Ltd
 
JavaOne 2016 :: Bringing Robot online with Robo4j Framework
JavaOne 2016 :: Bringing Robot online with Robo4j FrameworkJavaOne 2016 :: Bringing Robot online with Robo4j Framework
JavaOne 2016 :: Bringing Robot online with Robo4j FrameworkMiro Wengner
 
Rf meetup 16.3.2017 tampere share
Rf meetup 16.3.2017 tampere shareRf meetup 16.3.2017 tampere share
Rf meetup 16.3.2017 tampere shareMika Tavi
 
The Engines of Software Development: Testing and Test Driven Development
The Engines of Software Development: Testing and Test Driven DevelopmentThe Engines of Software Development: Testing and Test Driven Development
The Engines of Software Development: Testing and Test Driven DevelopmentLemi Orhan Ergin
 
The automated tests inside Openshift
The automated tests inside OpenshiftThe automated tests inside Openshift
The automated tests inside OpenshiftOleg Popov
 
ATDD Using Robot Framework
ATDD Using Robot FrameworkATDD Using Robot Framework
ATDD Using Robot FrameworkPekka Klärck
 
Functional Tests Automation with Robot Framework
Functional Tests Automation with Robot FrameworkFunctional Tests Automation with Robot Framework
Functional Tests Automation with Robot Frameworklaurent bristiel
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introductionlaurent bristiel
 
Fit for Work – key questions from employers
 Fit for Work – key questions from employers Fit for Work – key questions from employers
Fit for Work – key questions from employersFit for Work
 
ATAGTR2017 Expanding test horizons with Robot Framework
ATAGTR2017 Expanding test horizons with Robot FrameworkATAGTR2017 Expanding test horizons with Robot Framework
ATAGTR2017 Expanding test horizons with Robot FrameworkAgile Testing Alliance
 

Andere mochten auch (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Software architecture...Yes, on tests!
Software architecture...Yes, on tests!Software architecture...Yes, on tests!
Software architecture...Yes, on tests!
 
London SDET Meetup (April 2016) - M&S Digital Test Journey
London SDET Meetup (April 2016) - M&S Digital Test JourneyLondon SDET Meetup (April 2016) - M&S Digital Test Journey
London SDET Meetup (April 2016) - M&S Digital Test Journey
 
Pratap Kumar Nallamothu SDET2
Pratap Kumar Nallamothu SDET2Pratap Kumar Nallamothu SDET2
Pratap Kumar Nallamothu SDET2
 
Testing without Testers
Testing without TestersTesting without Testers
Testing without Testers
 
Appium & Robot Framework
Appium & Robot FrameworkAppium & Robot Framework
Appium & Robot Framework
 
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...
Agile Software Development and Test Driven Development: Agil8's Dave Putman 3...
 
JavaOne 2016 :: Bringing Robot online with Robo4j Framework
JavaOne 2016 :: Bringing Robot online with Robo4j FrameworkJavaOne 2016 :: Bringing Robot online with Robo4j Framework
JavaOne 2016 :: Bringing Robot online with Robo4j Framework
 
Belajar Postman test runner
Belajar Postman test runnerBelajar Postman test runner
Belajar Postman test runner
 
Rf meetup 16.3.2017 tampere share
Rf meetup 16.3.2017 tampere shareRf meetup 16.3.2017 tampere share
Rf meetup 16.3.2017 tampere share
 
Robot framework
Robot frameworkRobot framework
Robot framework
 
The Engines of Software Development: Testing and Test Driven Development
The Engines of Software Development: Testing and Test Driven DevelopmentThe Engines of Software Development: Testing and Test Driven Development
The Engines of Software Development: Testing and Test Driven Development
 
Robot Framework
Robot FrameworkRobot Framework
Robot Framework
 
The automated tests inside Openshift
The automated tests inside OpenshiftThe automated tests inside Openshift
The automated tests inside Openshift
 
ATDD Using Robot Framework
ATDD Using Robot FrameworkATDD Using Robot Framework
ATDD Using Robot Framework
 
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan PeshovJavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
 
Functional Tests Automation with Robot Framework
Functional Tests Automation with Robot FrameworkFunctional Tests Automation with Robot Framework
Functional Tests Automation with Robot Framework
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
 
Fit for Work – key questions from employers
 Fit for Work – key questions from employers Fit for Work – key questions from employers
Fit for Work – key questions from employers
 
ATAGTR2017 Expanding test horizons with Robot Framework
ATAGTR2017 Expanding test horizons with Robot FrameworkATAGTR2017 Expanding test horizons with Robot Framework
ATAGTR2017 Expanding test horizons with Robot Framework
 

Ähnlich wie An Introduction To Software Development - Test Driven Development, Part 1

An Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewAn Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewBlue Elephant Consulting
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentShawn Jones
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptxAmalEldhose2
 
Unit testing
Unit testingUnit testing
Unit testingPiXeL16
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptxmianshafa
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Conceptswesovi
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated TestingLars Thorup
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testingBestBrains
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingSahar Nofal
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonCefalo
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testingDuy Tan Geek
 
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAPABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAPABAPCodeRetreat
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven developmentEinar Ingebrigtsen
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentZendCon
 
Unit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUGUnit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUGegoodwintx
 

Ähnlich wie An Introduction To Software Development - Test Driven Development, Part 1 (20)

An Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewAn Introduction To Software Development - Final Review
An Introduction To Software Development - Final Review
 
Tdd
TddTdd
Tdd
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Tdd
TddTdd
Tdd
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
 
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAPABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
ABAPCodeRetreat Frankfurt 2016 - TDD with ABAP
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUGUnit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUG
 

Kürzlich hochgeladen

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 

Kürzlich hochgeladen (20)

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 

An Introduction To Software Development - Test Driven Development, Part 1

  • 1. An Introduction To Software Development Using Python Spring Semester, 2014 Class #13: Test Driven Development, Part 1
  • 2. 3 Different Types Of Testing • Unit Testing – Performed by developers – Goal is to ensure that their code works correctly • System Testing – Performed by professional testers – Goal is to ensure that the parts work together • User Testing – Performed by professional testers – Goal is to ensure that the expected functions work Image Credit www.fotosearch.com
  • 3. Python Has Two Testing Tools unittest • Automated testing framework • Python’s unittest module, sometimes referred to as PyUnit, is based on the XUnit framework design by Kent Beck and Erich Gamma. • The same pattern is repeated in many other languages, including C, perl, Java, and Smalltalk. • The framework implemented by unittest supports fixtures, test suites, and a test runner to enable automated testing for your code. Py.test • A mature full-featured Python testing tool • Provides easy no-boilerplate testing • Scales from simple unit to complex functional testing • Integrates with other testing methods and tools: • Extensive plugin and customization system:
  • 4. What Would A Py.Test Script Look Like For Homework #1? # # Encrypt the social security number encryptedSS = "" encryptedSS += socialSecurityNum[10] encryptedSS += socialSecurityNum[9] encryptedSS += socialSecurityNum[8] encryptedSS += socialSecurityNum[7] encryptedSS += socialSecurityNum[6] encryptedSS += socialSecurityNum[5] encryptedSS += socialSecurityNum[4] encryptedSS += socialSecurityNum[3] encryptedSS += socialSecurityNum[2] encryptedSS += socialSecurityNum[1] encryptedSS += socialSecurityNum[0] def test_encrypted_SS (): assert encryptedSS == ‘6270-55-461’ Image Credit www.objective.no
  • 5. What Is Continuous Integration? • Version control keeps track of our code • Now we have automated tests • We need to tie these two things together • Continuous Integration tools do the following: – Compile code – Run the automated tests – Display and mail out reports when new code is committed to the repository Image Credit www.guruintechnocrats.com
  • 6. Continuous Integration In Action Bob 1. Bob checks code into the server 2. Version control code notifies continuous integration tool that there is new code 3. Continuous integration tool checks out the new code, compiles it and runs all of your tests on it. Most build tools also create a web page and email the team to let them know how things are going.
  • 7. How Many Tests Do You Need? • Trade off: how much of the code that you test vs. the chances of finding a bug in the part that you haven’t tested. • Testing the same code several different ways won’t do you much good. • Don’t focus on the number of tests you have, instead focus on the coverage of your tests: % of code tested. • Most projects aim for 85% - 90% coverage Image Credit www.clker.com
  • 8. What If…? • Good software needs to work. • How do you know that your software works? • Even with unit testing, there is the possibility that a portion of your code is untested. • What if testing was a fundamental part of your software development process? • What if everything was done with testing in mind? • Version Control + Continuous Integration + Automated Testing
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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.
  • 13. 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.
  • 14. 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?
  • 15. 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.
  • 16. 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.
  • 17. 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.
  • 18. 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”
  • 19. 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
  • 20. 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
  • 21. 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?
  • 22. 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
  • 23. 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…
  • 24. 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/
  • 25. What We’ll Be Covering Next Time 1. Test driven development, Part 2 Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

Hinweis der Redaktion

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