SlideShare a Scribd company logo
Test Driven Development in Python




                         Anoop Thomas Mathew
                  Agiliq Info Solutions Pvt. Ltd.
Overview
●   About TDD
●   TDD and Python
●   unittests
●   Developing with Tests
●   Concluding Remarks
●   Open Discussion
“ Walking on water and developing software
  from a specification are easy if both are
  frozen. ” - Edward V Berard
About Test Driven Development
           (TDD)
●   Write tests for the use case
●   Run it (make sure it fails and fails
     miserably)
●   Write code and implement the required
     functionality with relevant level of detail
●   Run the test
●   Write test for addition features
●   Run all test
●   Watch it succeed. Have a cup of coffee !
Advantages of TDD

●   application is determined by using it
●   written minimal amount of application code
       –   total application + tests is probably more
       –   objects: simpler, stand-alone, minimal
             dependencies
●   tends to result in extensible architectures
●   instant feedback
Unittest
import unittest
class MyTest(unittest.TestCase):
    def testMethod(self):
        self.assertEqual(1 + 2, 3, "1 + 2 !=3")


if __name__ == '__main__':
    unittest.main()
import unittest

from demo import Greater                              The Test
class DemoTest(unittest.TestCase):

    def test_number(self):

        comparator = Greater()

        result = comparator.greater(10,5)

        self.assertTrue(result)

    def test_char(self):

        comparator = Greater()

        result = comparator.greater('abcxyz', 'AB')

        self.assertTrue(result)

    def test_char_equal(self):

        comparator = Greater()

        result = comparator.greater('4', 3)

        self.assertTrue(result)

if __name__ == '__main__':

    unittest.main()
class Greater(object):
                                           The Program
    def greater(self, val1, val2):

        if type(val1) ==str or type(val2) == str:

           val1 = str(val1)

           val2 = str(val2)

           sum1 = sum([ord(i) for i in val1])

           sum2 = sum([ord(i) for i in val2])

           if sum1 > sum2:

                return True

           else:

                return False

        if val1>val2:

            return True

        else:

            return False
Test Again


1. Add new test for features/bugs
2. Resolve the issue, make the test succeed.
3. Iterate from Step 1
Beware!!!
Murphy is everywhere.
Let's Discuss

More Related Content

What's hot

Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Kostja Osipov
 
The problem with tdd
The problem with tddThe problem with tdd
The problem with tdd
Dror Helper
 
The Art Of Debugging
The Art Of DebuggingThe Art Of Debugging
The Art Of Debugging
svilen.ivanov
 
Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18
Adi Bolboaca
 

What's hot (20)

Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
 
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź ...
 
Test Driven Development en Go con Ginkgo y Gomega
Test Driven Development en Go con Ginkgo y GomegaTest Driven Development en Go con Ginkgo y Gomega
Test Driven Development en Go con Ginkgo y Gomega
 
Learning to Enjoy Unit Testing
Learning to Enjoy Unit TestingLearning to Enjoy Unit Testing
Learning to Enjoy Unit Testing
 
Best practices for unit testing RxJava
Best practices for unit testing RxJavaBest practices for unit testing RxJava
Best practices for unit testing RxJava
 
Testing
TestingTesting
Testing
 
Obejct Oriented SCM - OOSCM
Obejct Oriented SCM - OOSCMObejct Oriented SCM - OOSCM
Obejct Oriented SCM - OOSCM
 
Introduction to Continuous Delivery
Introduction to Continuous DeliveryIntroduction to Continuous Delivery
Introduction to Continuous Delivery
 
The problem with tdd
The problem with tddThe problem with tdd
The problem with tdd
 
Day1 - TDD (Lecture SS 2015)
Day1 - TDD (Lecture SS 2015)Day1 - TDD (Lecture SS 2015)
Day1 - TDD (Lecture SS 2015)
 
TDD & Refactoring
TDD & RefactoringTDD & Refactoring
TDD & Refactoring
 
The Art Of Debugging
The Art Of DebuggingThe Art Of Debugging
The Art Of Debugging
 
TDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and Gomega
 
Go/Ruby/Java: What's next?
Go/Ruby/Java: What's next?Go/Ruby/Java: What's next?
Go/Ruby/Java: What's next?
 
Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18
 
Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Unit testing.pptx [repaired]
Unit testing.pptx [repaired]
 
Unit testing in PHP
Unit testing in PHPUnit testing in PHP
Unit testing in PHP
 
PHP unit testing - good and bad practices
PHP unit testing - good and bad practicesPHP unit testing - good and bad practices
PHP unit testing - good and bad practices
 
Los diez mandamientos de TDD
Los diez mandamientos de TDDLos diez mandamientos de TDD
Los diez mandamientos de TDD
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 

Similar to Test Driven Development in Python

Similar to Test Driven Development in Python (20)

Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittest
 
Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
Google test training
Google test trainingGoogle test training
Google test training
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Python testing
Python  testingPython  testing
Python testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
05 junit
05 junit05 junit
05 junit
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
P&MSP2012 - Unit Testing
P&MSP2012 - Unit TestingP&MSP2012 - Unit Testing
P&MSP2012 - Unit Testing
 
Python unit testing
Python unit testingPython unit testing
Python unit testing
 
Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With Python
 
Формальная верификация как средство тестирования (в Java)
Формальная верификация как средство тестирования (в Java)Формальная верификация как средство тестирования (в Java)
Формальная верификация как средство тестирования (в Java)
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Unit testing
Unit testingUnit testing
Unit testing
 
Software Testing for Data Scientists
Software Testing for Data ScientistsSoftware Testing for Data Scientists
Software Testing for Data Scientists
 

More from Anoop Thomas Mathew

More from Anoop Thomas Mathew (18)

Data Driven Code
Data Driven CodeData Driven Code
Data Driven Code
 
Writing Smarter Applications with Machine Learning
Writing Smarter Applications with Machine LearningWriting Smarter Applications with Machine Learning
Writing Smarter Applications with Machine Learning
 
Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in Python
 
Protoyping Painkiller Startups
Protoyping Painkiller StartupsProtoyping Painkiller Startups
Protoyping Painkiller Startups
 
ingenium
ingeniumingenium
ingenium
 
Web Development Fundamentals
Web Development FundamentalsWeb Development Fundamentals
Web Development Fundamentals
 
What The Web!
What The Web!What The Web!
What The Web!
 
Investor pitch deck for Vibe
Investor pitch deck for VibeInvestor pitch deck for Vibe
Investor pitch deck for Vibe
 
Getting Started on distributed version control with git
Getting Started on distributed version control with gitGetting Started on distributed version control with git
Getting Started on distributed version control with git
 
Let's Contribute
Let's ContributeLet's Contribute
Let's Contribute
 
Advanced Computing for Sustainable Future
Advanced Computing for Sustainable FutureAdvanced Computing for Sustainable Future
Advanced Computing for Sustainable Future
 
Ambidextrous Python - Introduction Python Libraries
Ambidextrous Python - Introduction Python Libraries Ambidextrous Python - Introduction Python Libraries
Ambidextrous Python - Introduction Python Libraries
 
Faster Python
Faster PythonFaster Python
Faster Python
 
Startups and FOSS
Startups and FOSSStartups and FOSS
Startups and FOSS
 
How slow is Real slow - PyCon India 2013
How slow is Real slow - PyCon India 2013 How slow is Real slow - PyCon India 2013
How slow is Real slow - PyCon India 2013
 
Redis way of Anayltics with Python - Fifth Elephant 2012
Redis way of Anayltics with Python - Fifth Elephant 2012Redis way of Anayltics with Python - Fifth Elephant 2012
Redis way of Anayltics with Python - Fifth Elephant 2012
 
Building a Company atop of Open Source
Building a Company atop of Open SourceBuilding a Company atop of Open Source
Building a Company atop of Open Source
 
Pycon 2012 Scikit-Learn
Pycon 2012 Scikit-LearnPycon 2012 Scikit-Learn
Pycon 2012 Scikit-Learn
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

Test Driven Development in Python

  • 1. Test Driven Development in Python Anoop Thomas Mathew Agiliq Info Solutions Pvt. Ltd.
  • 2. Overview ● About TDD ● TDD and Python ● unittests ● Developing with Tests ● Concluding Remarks ● Open Discussion
  • 3. “ Walking on water and developing software from a specification are easy if both are frozen. ” - Edward V Berard
  • 4. About Test Driven Development (TDD) ● Write tests for the use case ● Run it (make sure it fails and fails miserably) ● Write code and implement the required functionality with relevant level of detail ● Run the test ● Write test for addition features ● Run all test ● Watch it succeed. Have a cup of coffee !
  • 5. Advantages of TDD ● application is determined by using it ● written minimal amount of application code – total application + tests is probably more – objects: simpler, stand-alone, minimal dependencies ● tends to result in extensible architectures ● instant feedback
  • 6. Unittest import unittest class MyTest(unittest.TestCase): def testMethod(self): self.assertEqual(1 + 2, 3, "1 + 2 !=3") if __name__ == '__main__': unittest.main()
  • 7. import unittest from demo import Greater The Test class DemoTest(unittest.TestCase): def test_number(self): comparator = Greater() result = comparator.greater(10,5) self.assertTrue(result) def test_char(self): comparator = Greater() result = comparator.greater('abcxyz', 'AB') self.assertTrue(result) def test_char_equal(self): comparator = Greater() result = comparator.greater('4', 3) self.assertTrue(result) if __name__ == '__main__': unittest.main()
  • 8. class Greater(object): The Program def greater(self, val1, val2): if type(val1) ==str or type(val2) == str: val1 = str(val1) val2 = str(val2) sum1 = sum([ord(i) for i in val1]) sum2 = sum([ord(i) for i in val2]) if sum1 > sum2: return True else: return False if val1>val2: return True else: return False
  • 9. Test Again 1. Add new test for features/bugs 2. Resolve the issue, make the test succeed. 3. Iterate from Step 1